异常“组件不可用”迭代窗口对象的属性时
我正在尝试使用 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); };
I'm trying to convert a Google Chrome extension to Firefox using Addon SDK (Jetpack). The following code (run as content-script)
var property, winProperties = {};
for (property in window) {
winProperties[property] = true;
}
throws this exception when run in Firefox 5.0 and 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]
Does anyone know how to catch this exception or how to avoid the "problematic" property and continue the loop?
Note that I can't just put a try-catch statement in the loop's body, since even this triggers the error:
for (var property in window) {};
However if I execute the same or a similar statement in Firefox's "Web Console" then it runs fine:
for (var property in window) { console.log(property); };
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法通过测试安装测试用例扩展来重现此问题按钮,然后访问 http://example.org/ - 有一些属性打印到控制台,后面跟着消息“完成”,没有错误。
测试用例代码:
I couldn't reproduce this with a testcase extension by installing it via the Test button and then visiting http://example.org/ - there were some properties printed to the console, followed by the message "done", with no errors.
The testcase code: