Macos 可编写脚本的NPAPI插件不';不能使用Firefox

Macos 可编写脚本的NPAPI插件不';不能使用Firefox,macos,firefox,firefox-addon,npapi,firefox3.6,Macos,Firefox,Firefox Addon,Npapi,Firefox3.6,我正在开发FF扩展和插件,它们可以协同工作。我的扩展将npapi插件注入html,并在事件发生后调用插件的某些方法 以下是我用于注入的代码: if (window.content.document.getElementById("rondyoHookMessageElement") == null) { var element = window.content.document.createElement("object"); element.ty

我正在开发FF扩展和插件,它们可以协同工作。我的扩展将npapi插件注入html,并在事件发生后调用插件的某些方法

以下是我用于注入的代码:

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 element = window.content.document.getElementById("rondyoHookMessageElement");
element.SomeFunc();
我确认找到了元素,但是记录
元素。SomeFunc
返回
未定义的

如果我手动注入npapi插件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
</head>
<body>
<object id="plugin" type="application/plugin-mime" width=200 height=200 border=5></object>
<script type="text/javascript">
    var plugin = document.getElementById("plugin");
    dump(plugin.SomeFunc + "\n");
</script>
</body>
</html>

var plugin=document.getElementById(“插件”);
转储(plugin.SomeFunc+“\n”);
它返回
函数SomeFunc(){[native code]}

操作系统:Mac OS X 10.6.7


FF:3.6.13

如果在Firefox4中执行此操作,则有相当大的机会使浏览器崩溃(错误已被记录,但尚未修复)。在将对象标记注入DOM之前设置对象标记的类型不是一个好主意;您将在每个浏览器上获得不同的行为。等待将对象放入dom,然后注入它


另一个可能的问题是,将浏览器注入DOM后,有时需要一段时间才能访问插件,因此,如果使用setTimeout等待半秒左右,它可能会在该点开始工作。

我通过扩展调用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);
}
当我需要从扩展调用此函数时,我会:

window.content.document.defaultView.wrappedJSObject.f(null, mes, false);

已经有一些超时。我认为这是一个安全问题:扩展的JS代码不能使用注入页面html的NPAPI插件。但我不确定,我还没有测试过。