To help illustrate how to develop extensions, we maintain a repository of simple example extensions at https://github.com/mdn/webextensions-examples. This article describes the WebExtension APIs used in that repository.
These examples work in Firefox Nightly: most work in earlier versions of Firefox, but check the strict_min_version key in the extension's manifest.json to make sure.
If you want to try out these examples, you have three main choices:
- Clone the repository, then load the extension straight from its source directory, using the "Load Temporary Add-on" feature. The extension will stay loaded until you restart Firefox.
- Clone the repository, then use the web-ext command line tool to run Firefox with the extension installed.
- Clone the repository, then go to the build directory. This contains built and signed versions of all the examples, so you can just open them in Firefox (using File/Open File) and install them permanently, just like an extension you would install from addons.mozilla.org.
If you want to contribute to the repository, send us a pull request!
| Name | Description | JavaScript APIs |
|---|---|---|
| annotate-page | Displays a sidebar that lets you take notes on web pages. | storage.localtabs.onActivatedtabs.onUpdatedtabs.querywindows.getCurrent |
| apply-css | Adds a page action to the toolbar. Click the button to apply a red border using injected CSS. Click the button again to remove the CSS. | pageAction.getTitlepageAction.onClickedpageAction.setIconpageAction.setTitlepageAction.showtabs.insertCSStabs.onUpdatedtabs.querytabs.removeCSS |
| beastify | Adds a browser action icon to the toolbar. Click the button to choose a beast. The active tab's body content is then replaced with a picture of the chosen beast. | extension.getURLruntime.onMessagetabs.executeScripttabs.querytabs.reloadtabs.sendMessage |
| bookmark-it | Adds a bookmark button to the toolbar. Click the button to toggle a bookmark for the current page. | bookmarks.createbookmarks.onCreatedbookmarks.onRemovedbookmarks.removebookmarks.searchbrowserAction.onClickedbrowserAction.setIcontabs.onActivatedtabs.onUpdatedtabs.querywindows.onFocusChanged |
| borderify | Adds a solid red border to all webpages matching mozilla.org. | |
| chill-out | Show a page action after a period of inactivity. Show cat gifs when the page action is clicked. | alarms.clearAllalarms.createalarms.onAlarmpageAction.hidepageAction.onClickedpageAction.showtabs.gettabs.onActivatedtabs.onUpdatedtabs.querytabs.update |
| commands | Demonstrates using the commands API to set up a keyboard shortcut. The shortcut created is accessed using Ctrl+Shift+Y (Command+Shift+Y on a Mac). | commands.getAllcommands.onCommand |
| context-menu-copy-link-with-types | Add a context menu option to links to copy the link to the clipboard, as plain text and as a link in rich HTML. | contextMenus.createcontextMenus.onClickedtabs.executeScript |
| context-menu-demo | Demonstrates adding and manipulating context menu items using the contextMenus API. | contextMenus.createcontextMenus.onClickedcontextMenus.removecontextMenus.updatei18n.getMessageruntime.lastErrortabs.executeScript |
| contextual-identities | List, create, and remove contextual identities. | contextualIdentities.querytabs.createtabs.querytabs.remove |
| cookie-bg-picker | Allows the user to customize the background color and tiled pattern on sites the visit, and also saves their preferences via a cookie, reapplying them whenever they revisit a site they previously customized. | cookies.getcookies.onChangedcookies.removecookies.setextension.getURLruntime.onMessagetabs.onActivatedtabs.onUpdatedtabs.querytabs.sendMessage |
| dynamic-theme | Dynamic theme example | alarms.createalarms.onAlarmtheme.update |
| embedded-webextension-bootstrapped | Demonstrates how to use an embedded WebExtension to port from a bootstrapped extension. | runtime.onMessageruntime.sendMessagestorage.local |
| embedded-webextension-sdk | Demonstrates how to use an embedded WebExtension to port from an SDK-based add-on. | notifications.createruntime.connectruntime.onConnectruntime.onMessageruntime.sendMessagestorage.local |
| emoji-substitution | Replaces words with emojis. | |
| eslint-example | Demonstrates how to configure an extension with eslint. | |
| favourite-colour | An example options page, letting you store your favourite colour. | browserAction.onClickedruntime.openOptionsPagestorage.sync |
| firefox-code-search | Demonstrates how to use the omnibox API. | omnibox.onInputChangedomnibox.onInputEnteredomnibox.setDefaultSuggestiontabs.createtabs.update |
| forget-it | Demonstrates how to use the browsingData API. | browserAction.onClickedbrowsingData.removenotifications.createstorage.local |
| google-userinfo | Demonstrates how to use the identity API. | browserAction.onClickedidentity.getRedirectURLidentity.launchWebAuthFlownotifications.create |
| history-deleter | History API demo: deletes history items for a given domain | history.deleteUrlhistory.searchpageAction.showtabs.onUpdatedtabs.query |
| imagify | Using a sidebar, illustrates the use of file picker and drag and drop. A content script replaces the current page content with the chosen image. | runtime.onMessagetabs.executeScripttabs.querytabs.sendMessage |
| latest-download | Shows the last downloaded item, and lets you open or delete it. | downloads.erasedownloads.getFileIcondownloads.opendownloads.removeFiledownloads.search |
| list-cookies | This extensions list the cookies in the active tab. | cookies.getAlltabs.query |
| mocha-client-tests | This example shows two methods of testing an extension: running tests from within the extension, and running tests from the command line using Karma | runtime.sendMessage |
| native-messaging | Example of native messaging, including a Python application and an extension which exchanges messages with it. | browserAction.onClickedruntime.connectNative |
| navigation-stats | Demonstration of the webNavigation API, showing basic stats about which pages you've visited. | storage.localwebNavigation.onCompleted |
| notify-link-clicks-i18n | Shows a localized notification when the user clicks on links. | extension.getURLi18n.getMessagenotifications.createruntime.onMessageruntime.sendMessage |
| open-my-page-button | Adds a browser action icon to the toolbar. When the browser action is clicked, the add-on opens a page that was packaged with it. | browserAction.onClickedtabs.create |
| page-to-extension-messaging | Demonstrates how a web page and a content script can exchange messages. Visit https://mdn.github.io/webextensions-examples/content-script-page-script-messaging.html for the demo. | |
| permissions | Demonstrates optional permissions using the permissions API. | browserAction.onClickedpermissions.getAllpermissions.removepermissions.requestruntime.getURLtabs.create |
| proxy-blocker | Uses the proxy API to block requests to specific hosts. | extension.getURLproxy.onProxyErrorproxy.registerProxyScriptruntime.onMessageruntime.sendMessagestorage.localstorage.onChanged |
| quicknote | Allows the user to make quick notes by clicking a button and entering text into the resulting popup. The notes are saved in storage. | storage.local |
| react-es6-popup | This is an example of creating a browser action popup UI in React and ES6 JavaScript. | |
| selection-to-clipboard | Demonstrates how to write to the clipboard from a content script | |
| stored-credentials | Performs basic authentication by supplying stored credentials. | storage.localwebRequest.onAuthRequiredwebRequest.onCompletedwebRequest.onErrorOccurred |
| tabs-tabs-tabs | Demonstrates tab manipulation: opening, closing, moving, zooming tabs. | tabs.createtabs.duplicatetabs.getZoomtabs.highlighttabs.movetabs.onMovedtabs.onRemovedtabs.querytabs.reloadtabs.removetabs.setZoom |
| theme-switcher | An example of how to use the management API for themes. | management.getAllmanagement.setEnabled |
| themes | A collection of themes illustrating:
| |
| top-sites | Demonstration of the topSites API. | topSites.get |
| user-agent-rewriter | Demonstrates using the webRequest API to rewrite the User-Agent HTTP header. | extension.getBackgroundPagewebRequest.onBeforeSendHeaders |
| webpack-modules | Demonstrates how to use webpack to package npm modules in an extension. | runtime.onMessageruntime.sendMessage |
| window-manipulator | Demonstrates how to manipulate windows: opening, closing, resizing windows. | windows.createwindows.getAllwindows.getCurrentwindows.removewindows.update |
Document Tags and Contributors
Tags:
Contributors to this page:
andrewtruongmoz,
wbamberg,
Jorge.villalobos,
kumar303,
andymckay-github,
maybe
Last updated by:
andrewtruongmoz,