Top Related Projects
Example Firefox add-ons created using the WebExtensions API
Chrome Extensions Samples
🛠️ A Vue CLI 3+ preset (previously a Vue CLI 2 boilerplate) for quickly starting a web extension with Vue, Babel, ESLint and more!
🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
Quick Overview
Mozilla's web-ext is a command-line tool designed to help build, run, and test WebExtensions for Firefox and other compatible browsers. It streamlines the development process by providing a set of utilities for tasks such as linting, running, and packaging extensions.
Pros
- Simplifies the development workflow for WebExtensions
- Provides real-time reloading for faster development
- Includes built-in linting to catch common errors
- Supports cross-browser compatibility testing
Cons
- Limited to WebExtensions, not suitable for other types of browser add-ons
- May have a learning curve for developers new to command-line tools
- Some advanced features may require additional configuration
Getting Started
To get started with web-ext, follow these steps:
- Install Node.js and npm
- Install web-ext globally:
npm install --global web-ext
- Navigate to your extension's directory
- Run your extension in Firefox:
web-ext run
- To build a package for distribution:
web-ext build
For more detailed instructions and advanced usage, refer to the official documentation on the GitHub repository.
Competitor Comparisons
Example Firefox add-ons created using the WebExtensions API
Pros of webextensions-examples
- Provides a wide range of practical examples for various WebExtension APIs
- Ideal for learning and understanding different extension functionalities
- Regularly updated with new examples and best practices
Cons of webextensions-examples
- Not a development tool, but rather a collection of examples
- Lacks automated build and testing capabilities
- May require more setup and configuration for actual extension development
Code Comparison
web-ext:
const webExt = require('web-ext');
webExt.cmd.run({
sourceDir: '/path/to/your/extension/',
firefox: 'firefox-developer-edition',
browserConsole: true
}, {
shouldExitProgram: false,
});
webextensions-examples:
browser.browserAction.onClicked.addListener(() => {
browser.tabs.create({
url: "https://example.com"
});
});
The web-ext example shows how to use the tool for running and testing an extension, while the webextensions-examples code demonstrates a simple browser action implementation. web-ext focuses on development workflow, whereas webextensions-examples provides functional code snippets for specific extension features.
Chrome Extensions Samples
Pros of chrome-extensions-samples
- Extensive collection of sample extensions covering various APIs and use cases
- Official Google repository, ensuring up-to-date and best practice examples
- Includes both Manifest V2 and V3 samples for better compatibility
Cons of chrome-extensions-samples
- Focused solely on Chrome extensions, limiting cross-browser compatibility
- Lacks built-in development tools or command-line utilities
- Requires more manual setup and configuration for each sample
Code Comparison
web-ext:
const webExt = require('web-ext');
webExt.cmd.run({
sourceDir: '/path/to/your/extension/',
firefox: 'firefox-developer-edition',
browserConsole: true,
});
chrome-extensions-samples:
chrome.runtime.onInstalled.addListener(() => {
chrome.action.setBadgeText({
text: "OFF",
});
});
The web-ext code snippet demonstrates the ease of running and debugging an extension using the command-line tool. In contrast, the chrome-extensions-samples code shows a basic Chrome extension API usage, which requires manual setup and running in the browser.
web-ext provides a streamlined development experience with built-in tools, while chrome-extensions-samples offers a wide range of examples but requires more manual configuration. web-ext supports cross-browser development, whereas chrome-extensions-samples is Chrome-specific but offers more comprehensive API coverage.
🛠️ A Vue CLI 3+ preset (previously a Vue CLI 2 boilerplate) for quickly starting a web extension with Vue, Babel, ESLint and more!
Pros of vue-web-extension
- Specifically designed for Vue.js, providing a tailored development experience
- Includes hot-reloading for faster development cycles
- Offers a pre-configured webpack setup optimized for browser extensions
Cons of vue-web-extension
- Limited to Vue.js framework, less flexible for other technologies
- Smaller community and potentially fewer resources compared to web-ext
- May require more setup and configuration for non-Vue projects
Code Comparison
web-ext:
// web-ext run
const webExt = require('web-ext');
webExt.cmd.run({
sourceDir: './src',
firefox: 'firefox-developer-edition'
});
vue-web-extension:
// vue.config.js
module.exports = {
pages: {
popup: 'src/popup/popup.js',
options: 'src/options/options.js',
background: 'src/background.js'
},
pluginOptions: {
browserExtension: {
componentOptions: {
background: {
entry: 'src/background.js'
}
}
}
}
};
web-ext is a more general-purpose tool for developing browser extensions, supporting multiple browsers and technologies. It provides a straightforward CLI for common extension development tasks.
vue-web-extension, on the other hand, is specifically tailored for Vue.js developers, offering a more integrated experience with the Vue ecosystem. It includes features like hot-reloading and a pre-configured webpack setup, which can significantly speed up development for Vue-based extensions.
🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
Pros of web-extension-starter
- Provides a modern, TypeScript-based boilerplate for cross-browser extension development
- Includes pre-configured build tools and webpack for efficient development workflow
- Offers a more opinionated structure, which can speed up initial development
Cons of web-extension-starter
- Less flexible than web-ext for developers who prefer custom setups
- May have a steeper learning curve for beginners due to TypeScript and webpack configuration
- Lacks some of the advanced testing and debugging features provided by web-ext
Code Comparison
web-extension-starter:
import Browser from 'webextension-polyfill';
export async function getCurrentTab() {
const [tab] = await Browser.tabs.query({active: true, currentWindow: true});
return tab;
}
web-ext:
const webExtension = require('web-ext').default;
webExtension.cmd.run({
sourceDir: '/path/to/your/extension/',
firefox: 'firefox-developer-edition',
browserConsole: true
}, {
shouldExitProgram: false,
});
The code snippets highlight the different approaches:
- web-extension-starter focuses on providing a TypeScript-based environment for extension development
- web-ext offers a command-line interface for running and testing extensions directly
Both repositories aim to simplify browser extension development, but they cater to different developer preferences and project requirements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Web-ext
This is a command line tool to help build, run, and test WebExtensions.
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
- Open the
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: There is limited support for this API.
Aside from using web-ext on the command line, 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.
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,
},
);
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:
Top Related Projects
Example Firefox add-ons created using the WebExtensions API
Chrome Extensions Samples
🛠️ A Vue CLI 3+ preset (previously a Vue CLI 2 boilerplate) for quickly starting a web extension with Vue, Babel, ESLint and more!
🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot