web-ext is a free, open source browsers & extensions project written in JavaScript and released under MPL-2.0. It has 3,138 GitHub stars, 385 forks and 223 open issues, and was last pushed 15 hours ago. On this registry it ranks #51 of 65 tracked projects in Browsers & Extensions, with 5 head-to-head comparisons available. It gained 1 stars over the last 3 tracked days.

What is web-ext?

What it is

web-ext is a command line tool for building, running, and testing WebExtensions. It lives in the JavaScript and npm ecosystem, and it targets browser add-ons that use the WebExtensions API. The project is licensed under MPL-2.0 and is distributed through npm, with an unofficial Homebrew formula maintained by the community. It provides one command line interface for common extension development tasks.

The problem it solves is repetitive manual work when loading, validating, packaging, and signing browser extensions during development. web-ext groups those actions into named commands such as run, lint, sign, build, and docs. Its initial focus is Firefox Extensions, while its stated aim is standard, portable, cross-platform browser extension support.

Key capabilities

  • The run command loads an extension from a local source directory, with arguments such as --source-dir and --firefox=nightly.
  • The lint command validates extension source code.
  • The build command creates an extension package from source files.
  • The sign command signs an extension so it can be installed in Firefox.
  • The docs command opens the web-ext documentation in a browser from the command line.
  • web-ext can be installed as a devDependency and invoked through npm scripts, which lets a team pin the tool version.

Who uses it and how

  • Firefox extension developers use web-ext run while iterating on an add-on, pointing the command at a local source directory.
  • Extension teams add web-ext as a devDependency and call it from npm scripts, so contributors use the same command and version.
  • Extension authors use web-ext lint before packaging, then web-ext build to create a package, or web-ext sign for a Firefox-installable build.
  • Repository contributors can clone the source, install dependencies with npm ci, build the command, and link it for local use.

Getting started

Install web-ext globally with npm install --global web-ext, or add it to a project with npm install --save-dev web-ext and run it through an npm script. The README also documents an unofficial Homebrew formula and source installation with npm ci, npm run build, and npm link.

When to use it — and when not to

Use web-ext when your workflow is command-line based and centered on WebExtensions, especially Firefox development. Avoid it as a stable internal NodeJS API, because direct use has limited support and backward incompatible changes may appear in minor or patch updates. Its cross-platform aim is stated, but the README presents Firefox Extensions as the initial focus.

project readme (upstream, from github) — read inline

Web-ext

This is a command line tool to help build, run, and test WebExtensions.

CircleCI codecov npm version

Ultimately, it aims to support browser extensions in a standard, portable, cross-platform way. Initially, it will provide a streamlined experience for developing Firefox Extensions.

Documentation

Here are the commands you can run. Click on each one for detailed documentation or use --help on the command line, such as web-ext build --help.

  • run
    • Run the extension
  • lint
    • Validate the extension source
  • sign
    • Sign the extension so it can be installed in Firefox
  • build
    • Create an extension package from source
  • docs
    • Open the web-ext documentation in a browser

Installation

Using npm

First, make sure you are running the current LTS (long term support) version of NodeJS.

Global command

You can install this command onto your machine globally with:

npm install --global web-ext
For your project

Alternatively, you can install this command as one of the devDependencies of your project. This method can help you control the version of web-ext as used by your team.

npm install --save-dev web-ext

Next you can use the web-ext command in your project as an npm script. Here is an example where the --source-dir argument specifies where to find the source code for your extension.

package.json

"scripts": {
  "start:firefox": "web-ext run --source-dir ./extension-dist/",
}

You can always pass in additional commands to your npm scripts using the -- suffix. For example, the previous script could specify the Firefox version on the command line with this:

npm run start:firefox -- --firefox=nightly

Using Homebrew (unofficial)

The community maintains a web-ext formula.

brew install web-ext

Installation from source

You'll need:

Optionally, you may like:

  • nvm, which helps manage node versions

If you had already installed web-ext from npm, you may need to uninstall it first:

npm uninstall --global web-ext

Change into the source and install all dependencies:

git clone https://github.com/mozilla/web-ext.git
cd web-ext
npm ci

Build the command:

npm run build

Link it to your node installation:

npm link

You can now run it from any directory:

web-ext --help

To get updates, just pull changes and rebuild the executable. You don't need to relink it.

cd /path/to/web-ext
git pull
npm run build

Using web-ext in NodeJS code

Note: web-ext is primarily a command line tool and there is limited support for direct use of its internal API. Backward incompatible changes may be introduced in minor and patch version updates to the web-ext npm package.

Aside from [using web-ext on the command line][web-ext-user-docs], you may wish to execute web-ext in NodeJS code.

As of version 7.0.0, the web-ext npm package exports NodeJS native ES modules only. If you are using CommonJS, you will have to use [dynamic imports][dynamic-imports].

Examples

You are able to execute command functions without any argument validation. If you want to execute web-ext run you would do so like this:

import webExt from 'web-ext';

webExt.cmd
  .run(
    {
      // These are command options derived from their CLI conterpart.
      // In this example, --source-dir is specified as sourceDir.
      firefox: '/path/to/Firefox-executable',
      sourceDir: '/path/to/your/extension/source/',
    },
    {
      // These are non CLI related options for each function.
      // You need to specify this one so that your NodeJS application
      // can continue running after web-ext is finished.
      shouldExitProgram: false,
    },
  )
  .then((extensionRunner) => {
    // The command has finished. Each command resolves its
    // promise with a different value.
    console.log(extensionRunner);
    // You can do a few things like:
    // extensionRunner.reloadAllExtensions();
    // extensionRunner.exit();
  });

If you would like to run an extension on Firefox for Android:

import * as adbUtils from "web-ext/util/adb";

// Path to adb binary (optional parameter, auto-detected if missing)
const adbBin = "/path/to/adb";
// Get an array of device ids (Array<string>)
const deviceIds = await adbUtils.listADBDevices(adbBin);
const adbDevice = ...
// Get an array of Firefox APKs (Array<string>)
const firefoxAPKs = await adbUtils.listADBFirefoxAPKs(
  deviceId, adbBin
);
const firefoxApk = ...

webExt.cmd.run({
  target: 'firefox-android',
  firefoxApk,
  adbDevice,
  sourceDir: ...
}).then((extensionRunner) => {...});

If you would like to control logging, you can access the logger object. Here is an example of turning on verbose logging:

import * as webExtLogger from 'web-ext/util/logger';

webExtLogger.consoleStream.makeVerbose();
webExt.cmd.run({ sourceDir: './src' }, { shouldExitProgram: false });

You can also disable the use of standard input:

webExt.cmd.run({ noInput: true }, { shouldExitProgram: false });

web-ext is designed for WebExtensions but you can try disabling manifest validation to work with legacy extensions. This is not officially supported.

webExt.cmd.run(
  { sourceDir: './src' },
  {
    getValidatedManifest: () => ({
      name: 'some-fake-name',
      version: '1.0.0',
    }),
    shouldExitProgram: false,
  },
);

You can also use webExt.cmd.sign() to request a signed xpi for a given extension source directory:

webExt.cmd.sign({
  // NOTE: Please set userAgentString to a custom one of your choice.
  userAgentString: 'YOUR-CUSTOM-USERAGENT',
  apiKey,
  apiSecret,
  amoBaseUrl: 'https://addons.mozilla.org/api/v5/',
  sourceDir: ...,
  channel: 'unlisted',
  ...
});

You can also access the internal signing module directly if you need to submit an xpi file without also building it. Note: submit-addon is internal web-ext module, using the webExt.cmd.sign() is the recommended API method.

import { signAddon } from 'web-ext/util/submit-addon';

signAddon({
  // NOTE: Please set userAgentString to a custom one of your choice.
  userAgentString: 'YOUR-CUSTOM-USERAGENT',
  apiKey,
  apiSecret,
  amoBaseUrl: 'https://addons.mozilla.org/api/v5/',
  id: '[email protected]',
  xpiPath: pathToExtension,
  savedUploadUuidPath: '.amo-upload-uuid',
  channel: 'unlisted',
});

Should I Use It?

Yes! The web-ext tool enables you to build and ship extensions for Firefox. This platform stabilized in Firefox 48 which was released in April of 2016.

Get Involved

Hi! This tool is under active development. To get involved you can watch the repo, file issues, create pull requests, or contact us to ask a question. Read the contributing section for how to develop new features.

Some Questions and Answers

Why do we need a command line tool?

This is a great question and one that we will ask ourselves for each new web-ext feature. Most WebExtension functionality is baked into the browsers themselves but a complimentary command line tool will still be helpful. Here is a partial list of examples:

readme truncated — read the full docs on github

Frequently asked questions

Is web-ext free to use?

web-ext is open source under the MPL-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does web-ext do?

A command line tool to help build, run, and test web extensions

What is web-ext written in?

web-ext is primarily written in JavaScript. Its source is publicly available at https://github.com/mozilla/web-ext, and it has 3,138 GitHub stars.