Scriptable NPAPI plugin doesn't work with Firefox

后端 未结 2 1261
清歌不尽
清歌不尽 2020-12-21 18:48

I\'m developing FF extension and plugin that work in tandem. My Extension injects npapi plugin into the html and calls some method of the plugin after an event occures.

相关标签:
2条回答
  • 2020-12-21 19:08

    I solved the problem by extending script which make a call of the SomeFunc:

    if (window.content.document.getElementById("rondyoHookMessageElement") == null) {
                var element = window.content.document.createElement("object");
                element.type = "application/x-hook-msg";
                element.id = "rondyoHookMessageElement";
                element.width = 0;
                element.height = 0;
                window.content.document.body.appendChild(element);
    
                var script = doc.createElement("script");
                script.type = "text/javascript";
                script.innerHTML = 'function f(doc, messageId, data) { document.getElementById("rondyoHookMessageElement").SomeFunc(doc, messageId, data); };';
                doc.body.appendChild(script);
    }
    

    When I need to call this function from the extension I do:

    window.content.document.defaultView.wrappedJSObject.f(null, mes, false);
    
    0 讨论(0)
  • 2020-12-21 19:13

    If you do this in FireFox 4 you have a decent chance of crashing the browser (the bug has been logged, but not yet fixed). it's not a good idea to set the type of the object tag before injecting it into the DOM; you'll get different behavior on each browser. Wait until you've put the object into the dom and then inject it.

    Another possible problem is that it sometimes takes the browser some time after injecting it into the DOM before the plugin is accessible, so if you use a setTimeout to wait for a half second or so it might start working at that point.

    0 讨论(0)
提交回复
热议问题