I have a large and complex XUL-based addon for which I need to use a few functions from the Add-on SDK. Is this possible? If so, does anyone have working sample code, preferably using the page-worker module?
Asked
Active
Viewed 277 times
1 Answers
4
The following is the way devtools does it, but certain modules will choke (the obvious candidate being self
). I think you will have better luck with low-level modules.
let {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
let loader = new Loader.Loader({
paths: {
"": "resource://gre/modules/commonjs/"
},
globals: {},
});
let require = Loader.Require(loader, { id: "myaddon" })
// now you can require addon-sdk modules

paa
- 5,048
- 1
- 18
- 22
-
1The documentation is here, FYI: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/toolkit/loader.html – therealjeffg Sep 07 '13 at 04:05
-
When I run this with the page-worker module, I get "TypeError: rootURI is undefined". – rednoyz Sep 07 '13 at 04:56