Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox Addon: bootstrap.js mit sdk/page-mod for versions < 38.0

tl;dr: We created a firefox addon using the Addon SDK. Since compiling the addon is one step in a larger build system (we also compile for chrome), our build system packages the xpi manually and does not use jpm. However, we used the contents of a jpm packaged addon as a template for writing our own addon. This only works for firefox >=38. Is there an easy way to make it work for earlier versions?

Details:

So we package an xpi file that contains the following bootstrap.js:

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

const { utils: Cu } = Components;
const rootURI = __SCRIPT_URI_SPEC__.replace("bootstrap.js", "");
const COMMONJS_URI = "resource://gre/modules/commonjs";
const { require } = Cu.import(COMMONJS_URI + "/toolkit/require.js", {});
const { Bootstrap } = require(COMMONJS_URI + "/sdk/addon/bootstrap.js");
const { startup, shutdown, install, uninstall } = new Bootstrap(rootURI);

Furthermore, the xpi contains an index.js with the actual code. This index.js is then setting up content scripts for sdk/page-mod.

So in the bootstrap.js, the startup/shutdown functions are linked to a Bootstrap object, which then handles enabling/disabling of the plugin.

This works fine in firefox 40, but I tested it with versions before 38 and it doesn't work, because it can't run the bootstrap.js script.

Is there a simple way to get it working for earlier firefox versions? It'S unfortunately quite hard to find documentation on this. Specificially, we don't want to break enabling/disabling the addon, i.e. if a user disables the addon, then the page-mod should be disabled too (as the Bootstrap class does it), and when enabling the plugin, it should be enabled again.

like image 812
Heinzi Avatar asked Dec 10 '25 19:12

Heinzi


1 Answers

Exposing require as a JSM was only introduced recently, so you're simply using new functionality for your approach.

For older versions you will have to create a custom Loader instance instead which can then be used to require things.

like image 140
the8472 Avatar answered Dec 13 '25 09:12

the8472



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!