Scriptable NPAPI plugin doesn't work with Firefox

拟墨画扇 提交于 2019-11-29 16:47:16

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.

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!