Skip to content Skip to sidebar Skip to footer

Services.wm Is Undefined (firefox Sdk Extension)

I get an error TypeError: Services.wm is undefined, when I use Firefox Addon SDK (JPM), and the following code in index.js: var self = require('sdk/self'); const { Cu } = require('

Solution 1:

Cu.import doesn't work as you think it does. Its return value is the global object of the imported module.

Normally the exported symbols of the module are imported as properties of the second object if specified or into the current global if not, which would define Services, which you then immediately replace with the return value.

Simply useing Cu.import("resource://gre/modules/Services.jsm", this);, without its return value, will work and import all exported symbols from that module.

The following form using destructuring assignment works, but is discouraged because it reaches into the target module's global and gets the constants instead of only accessing the exported symbols:

const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});

The SDK way of doing this properly is

const {Services} = require("resource://gre/modules/Services.jsm");

Post a Comment for "Services.wm Is Undefined (firefox Sdk Extension)"