开发者

Exception "Component is not available" when iterating over window object's properties

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开发者_StackOverflow 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); };


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:

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");'
    });
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜