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,
contentis 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 addresourcesubstitutions.The stuff that Erik wrote uses a custom
includefunction, 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.unloadyet.Using
content+Cu.import+Cu.unloadis 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
requireloader, so don't get distracted by that).chrome.manifest- usingcontentbootstrap.js- usingCu.importwith acontentchrome-URI.