javascript – 迭代窗口对象的属性时出现异常“组件不可用”
作者:互联网
我正在尝试使用Addon SDK(Jetpack)将Google Chrome扩展程序转换为Firefox.以下代码(作为content-script运行)
var property, winProperties = {};
for (property in window) {
winProperties[property] = true;
}
在Firefox 5.0和6.0中运行时抛出此异常:
Traceback (most recent call last):
File "sfc-bgcore.js", line 299, in null
File "resource://jid1-q4cqhvcl3sc4vq-at-jetpack-api-utils-lib/content/content-proxy.js", line 519, in null
for each (name in Object.keys(obj)) {
[Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
resource://jid1-q4cqhvcl3sc4vq-at-jetpack-api-utils-lib/securable-module.js ->
resource://jid1-q4cqhvcl3sc4vq-at-jetpack-api-utils-lib/content/content-proxy.js ::
<TOP_LEVEL> ::
line 519" data: no]
有谁知道如何捕获此异常或如何避免“有问题”属性并继续循环?
请注意,我不能在循环体中放置try-catch语句,因为即使这会触发错误:
for (var property in window) {};
但是,如果我在Firefox的“Web控制台”中执行相同或类似的语句,那么它运行正常:
for (var property in window) { console.log(property); };
解决方法:
我无法使用a testcase extension通过测试按钮安装它然后访问http://example.org/来重现这一点 – 有一些属性打印到控制台,然后是消息“完成”,没有错误.
测试用例代码:
exports.main = function(options, callbacks) {
var pageMod = require("page-mod");
pageMod.PageMod({
include: "*.org",
contentScript: 'for (property in window) {console.log(property)}; console.log("done");'
});
};
标签:javascript,firefox,firefox-addon,firefox-addon-sdk,window-object 来源: https://codeday.me/bug/20190710/1418727.html