3

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.

Heinzi
  • 5,793
  • 4
  • 40
  • 69

1 Answers1

3

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.

the8472
  • 40,999
  • 5
  • 70
  • 122
  • Hm I tried and failed. Is there a simple addon demo/example that just injects a content script and works for firefox < 38.0? – Heinzi Oct 12 '15 at 01:53
  • well, you're doing something very unconventional, so why would there be an example for your case? Anyway, before FF38 addons were packaged with cfx and not jpm, so maybe you can build one with that and have a look at its internals. – the8472 Oct 12 '15 at 06:57