Maintained by the MDN team at Mozilla.
WebExtensions are a way to write browser extensions: that is, programs installed inside a web browser that modify the behaviour of the browser or of web pages loaded by the browser. They are built on a set of cross-browser APIs, so WebExtensions written for Google Chrome or Opera will in most cases run in Firefox or Edge too.
The "webextensions-examples" repository is a collection of simple but complete and installable WebExtensions. You can use the examples to see how to use the WebExtensions APIs, and as a starting point for your own WebExtensions.
The examples are made available under the Mozilla Public License 2.0.
How to use "webextensions-examples"
To use the repository, first clone it.
Each example is in its own top-level directory. Install an example in your favourite web browser (installation instructions are below), and see how it works. Each example has its own short README explaining what it does.
To find your way around a WebExtension's internal structure, have a look at the Anatomy of a WebExtension page on MDN.
To use these examples in Firefox, you should use the most recent release of Firefox. Some examples work with earlier releases.
A few examples rely on APIs that are currently only available in pre-release versions of Firefox. Where this is the case, the example should declare the minimum version that it needs in the
strict_min_version part of the applications key in its manifest.json file.
Installing an example
There are a couple ways to try out the example extensions in this repository.
- Open Firefox and load
about:debuggingin the URL bar. Click the Load Temporary Add-on button and select the
manifest.jsonfile within the directory of an example extension you'd like to install. Here is a video that demonstrates how to do this.
- Install the web-ext tool, change into the directory of the example extension you'd like to install, and type
web-ext run. This will launch Firefox and install the extension automatically. This tool gives you some additional development features such as automatic reloading.
Index of examples
- Sidebar demo.
- Inserts CSS into a web page.
- Adds a browser action with a popup and injects a script into a web page.
- Adds and removes bookmarks.
- Injects scripts into pages that match a URL pattern.
Page action demo, plus some features of
- Defines keyboard shortcuts.
- Advanced clipboard interaction, including copy to clipboard from a background page.
- Adds items to the context menu.
- Contextual identities (containers) demo.
- Demo using cookies, browser actions with popups, and content scripts.
- An embedded WebExtension in a bootstrapped Firefox add-on.
- An embedded WebExtension in an Add-on SDK Firefox add-on.
- Injects content scripts into web pages matching a given URL pattern.
- How to configure a WebExtension with eslint.
- Demo of storage and options(settings) pages.
- Customizes the behavior of the browser's address bar.
- Clears stored browsing data.
- Authenticates the user with Google.
- Clears browsing history entries by domain.
- Displays the most recently downloaded item.
- Lists all cookies in the active tab.
- Tests the add-on using Mocha.
- Exchanges messages between the add-on and a Python program installed on the user's computer.
- Collects and displays statistics for sites the user navigates to.
- Displays localized notifications when the user clicks on links.
- Opens a page bundled with the add-on, when the user clicks a toolbar button.
- Exchanges messages between a web page and the add-on.
- Demo showing how to ask the user for additional permissions at runtime.
- Note-taking add-on: shows how to store data, and how to use browser actions and popups.
- How to use React and ES6 in an add-on.
- Basic clipboard example: copying to the clipboard in a content script.
- Performs HTTP basic authentication using a stored username and password.
Demo of various
tabsfunctions: open, close, move, etc.
- Replaces the "new tab" page with links to pages that the user often visits.
- Intercepts and modifies HTTP requests.
- Uses webpack to package npm modules for use in an add-on.
Demo of various
windowsfunctions: create, close, resize, etc.
To learn more about developing WebExtensions, see the WebExtensions documentation on MDN for getting started guides, tutorials, and full API reference docs.
If you find a problem, please file a bug.
If you need help, email the dev-addons mailing list or contact the WebExtensions team in the #webextensions IRC channel on irc.mozilla.org.
We welcome contributions, whether they are whole new examples, new features, bug fixes, or translations of localizable strings into new languages. Please see the CONTRIBUTING.md file for more details.