This is a spin-off of the Firefox Monitor Shield Study addon (https://github.com/mozilla/blurts-addon). The goal is to provide a starting point to engineer real Firefox features in WebExtension form for conducting Shield studies.
- Minimal template for studies that require the control and versatility of a bootstrap addon
- Basic Shield wrapper/boilerplate
- Painless, packaged l10n
- Painless Telemetry via the actual Shield API
- Basic directory structure and build setup (including eslint)
- Use an unbranded build for testing - see
https://wiki.mozilla.org/Add-ons/Extension_Signing#Unbranded_Builds
- Fork the repo
- Change add-on specific metadata in
package.json
andsrc/manifest.json
$npm install
$export FIREFOX_BINARY=/path/to/unbranded/firefox/binary
$npm start
$npm run build
- Just look at
Experiment.jsm
. You might not need to mess with anything else. :) - Strings are attempted to be loaded from
locales/${AppConstants.INSTALL_LOCALE}/strings.properties
, falling back tolocales/en-US/strings.properties
. - Add strings to
strings.properties
files inlocales/foo-BAR/
and usegetString()
andgetFormattedString()
to work with strings. - Send Telemetry using
sendTelemetry()
. Read on for details about how it works. - If you are confused by the scoping mechanisms and
Globals.jsm
, read on.
- This template implements a WebExtension Experiment API called
firefoxhooks
, accessible viabrowser.firefoxhooks
. - The API provides a simple event listener mechanism that allows passing objects from the privileged context to the extension context. Search for
gEventListener
inbackground.js
. The event mechanism is used in the template for Telemetry, but can probably easily be repurposed. Globals.jsm
is the entry point of the shared scope into which Firefox code is to be plugged.Globals.jsm
is loaded immediately upon addon installation from thefirefoxhooks API
implementation (api.js
).ChromeUtils.import
doesn't seem to work for resources that are packaged in an archive, soServices.scriptloader.loadSubScript
is substituded everywhere. The imports are done in a way thatGlobals.jsm
,FirefoxHooks.jsm
, andExperiment.jsm
all share the same global scope.FirefoxHooks.jsm
implements the WEE API, and tellsExperiment.jsm
when toinit()
andcleanup()
.- Shield studies are not supposed to be re-installed after the add-on is disabled/uninstalled by the user.
FirefoxHooks.jsm
takes care of nuking the addon installation if this happens.