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

4

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); };
javascript
firefox
firefox-addon
firefox-addon-sdk
window-object
asked on Stack Overflow Aug 12, 2011 by magnoz • edited Jun 2, 2012 by Wladimir Palant

1 Answer

1

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");'
    });
};
answered on Stack Overflow Sep 3, 2011 by Nickolay

User contributions licensed under CC BY-SA 3.0