I'm working on a bootstrapped extension for firefox for android and I want to import a js file to the bootstap.js (like importing a component in xul extensions). The classic method of using the chrome.manifest to use a resource alia is not allowed for bootstrapped extensions. I tried this code of Erik Vold but it doesn't seem to work
function startup(data) AddonManager.getAddonByID(data.id, function(addon) {
// Include some utility functions
include(addon.getResourceURI("includes/scanner.js").spec);
});
I really appreciate some help and thank you.
Actually,
content
is supported in bootstrapped add-ons since quite some time (first in Gecko 8 and starting with Gecko 10, it will auto load manifests, IIRC). You can load js code modules fromchrome://yourpackage/content/...
not just from resource-URIs (since Gecko 4, IIRC). So there is nothing holding you back from using mozilla-style code modules. Also, a couple of add-ons manually addresource
substitutions.The stuff that Erik wrote uses a custom
include
function, implemented in the corresponding bootstrap.js usingloadSubScript
. That's an option, too. This scheme was invented when it wasn't yet possible to use js code modules from bootstrapped add-ons properly, e.g. because there was noCu.unload
yet.Using
content
+Cu.import
+Cu.unload
is likely the easiest approach.Real world example in one of my own add-ons (Desktop + Android) (the rest of the add-on is written using a custom commonjs-style
require
loader, so don't get distracted by that).chrome.manifest
- usingcontent
bootstrap.js
- usingCu.import
with acontent
chrome-URI.