我正在尝试使用Addon SDK (Jetpack)将Google Chrome扩展转换为Firefox。以下代码(作为内容脚本运行)
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); };
我无法通过testcase扩展通过测试按钮安装它,然后访问http://example.org/-有一些属性打印到控制台,然后是消息"done",没有错误。
测试用例代码: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");'
});
};