• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
Add-ons
  1. MDN
  2. Mozilla
  3. Add-ons
  4. Browser extensions
  5. Example extensions

Example extensions

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:

  1. 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.
  2. Clone the repository, then use the web-ext command line tool to run Firefox with the extension installed.
  3. 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.local
tabs.onActivated
tabs.onUpdated
tabs.query
windows.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.getTitle
pageAction.onClicked
pageAction.setIcon
pageAction.setTitle
pageAction.show
tabs.insertCSS
tabs.onUpdated
tabs.query
tabs.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.getURL
runtime.onMessage
tabs.executeScript
tabs.query
tabs.reload
tabs.sendMessage
bookmark-it Adds a bookmark button to the toolbar. Click the button to toggle a bookmark for the current page. bookmarks.create
bookmarks.onCreated
bookmarks.onRemoved
bookmarks.remove
bookmarks.search
browserAction.onClicked
browserAction.setIcon
tabs.onActivated
tabs.onUpdated
tabs.query
windows.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.clearAll
alarms.create
alarms.onAlarm
pageAction.hide
pageAction.onClicked
pageAction.show
tabs.get
tabs.onActivated
tabs.onUpdated
tabs.query
tabs.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.getAll
commands.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.create
contextMenus.onClicked
tabs.executeScript
context-menu-demo Demonstrates adding and manipulating context menu items using the contextMenus API. contextMenus.create
contextMenus.onClicked
contextMenus.remove
contextMenus.update
i18n.getMessage
runtime.lastError
tabs.executeScript
contextual-identities List, create, and remove contextual identities. contextualIdentities.query
tabs.create
tabs.query
tabs.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.get
cookies.onChanged
cookies.remove
cookies.set
extension.getURL
runtime.onMessage
tabs.onActivated
tabs.onUpdated
tabs.query
tabs.sendMessage
dynamic-theme Dynamic theme example alarms.create
alarms.onAlarm
theme.update
embedded-webextension-bootstrapped Demonstrates how to use an embedded WebExtension to port from a bootstrapped extension. runtime.onMessage
runtime.sendMessage
storage.local
embedded-webextension-sdk Demonstrates how to use an embedded WebExtension to port from an SDK-based add-on. notifications.create
runtime.connect
runtime.onConnect
runtime.onMessage
runtime.sendMessage
storage.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.onClicked
runtime.openOptionsPage
storage.sync
firefox-code-search Demonstrates how to use the omnibox API. omnibox.onInputChanged
omnibox.onInputEntered
omnibox.setDefaultSuggestion
tabs.create
tabs.update
forget-it Demonstrates how to use the browsingData API. browserAction.onClicked
browsingData.remove
notifications.create
storage.local
google-userinfo Demonstrates how to use the identity API. browserAction.onClicked
identity.getRedirectURL
identity.launchWebAuthFlow
notifications.create
history-deleter History API demo: deletes history items for a given domain history.deleteUrl
history.search
pageAction.show
tabs.onUpdated
tabs.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.onMessage
tabs.executeScript
tabs.query
tabs.sendMessage
latest-download Shows the last downloaded item, and lets you open or delete it. downloads.erase
downloads.getFileIcon
downloads.open
downloads.removeFile
downloads.search
list-cookies This extensions list the cookies in the active tab. cookies.getAll
tabs.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.onClicked
runtime.connectNative
navigation-stats Demonstration of the webNavigation API, showing basic stats about which pages you've visited. storage.local
webNavigation.onCompleted
notify-link-clicks-i18n Shows a localized notification when the user clicks on links. extension.getURL
i18n.getMessage
notifications.create
runtime.onMessage
runtime.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.onClicked
tabs.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.onClicked
permissions.getAll
permissions.remove
permissions.request
runtime.getURL
tabs.create
proxy-blocker Uses the proxy API to block requests to specific hosts. extension.getURL
proxy.onProxyError
proxy.registerProxyScript
runtime.onMessage
runtime.sendMessage
storage.local
storage.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.local
webRequest.onAuthRequired
webRequest.onCompleted
webRequest.onErrorOccurred
tabs-tabs-tabs Demonstrates tab manipulation: opening, closing, moving, zooming tabs. tabs.create
tabs.duplicate
tabs.getZoom
tabs.highlight
tabs.move
tabs.onMoved
tabs.onRemoved
tabs.query
tabs.reload
tabs.remove
tabs.setZoom
theme-switcher An example of how to use the management API for themes. management.getAll
management.setEnabled
themes A collection of themes illustrating:
  • weta_fade: a basic theme employing a single image specified in headerURL:.
  • weta_fade_chrome: the weta_fade theme implemented with Chrome compatible manifest keys.
  • weta_tiled: a theme using a tiled image.
  • weta_mirror: a theme using multiple images and aligning those images in the header.
  • animated: use of an animated PNG.
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.getBackgroundPage
webRequest.onBeforeSendHeaders
webpack-modules Demonstrates how to use webpack to package npm modules in an extension. runtime.onMessage
runtime.sendMessage
window-manipulator Demonstrates how to manipulate windows: opening, closing, resizing windows. windows.create
windows.getAll
windows.getCurrent
windows.remove
windows.update

Document Tags and Contributors

Tags: 
  • WebExtensions
 Contributors to this page: andrewtruongmoz, wbamberg, Jorge.villalobos, kumar303, andymckay-github, maybe
 Last updated by: andrewtruongmoz, Jul 6, 2017, 11:02:50 AM
See also
  1. Browser extensions
  2. Getting started
    1. What are extensions?
    2. Your first extension
    3. Your second extension
    4. Anatomy of an extension
    5. Example extensions
  3. How to
    1. Intercept HTTP requests
    2. Modify a web page
    3. Add a button to the toolbar
    4. Implement a settings page
  4. User interface
    1. Introduction
    2. Toolbar button
    3. Address bar button
    4. Sidebar
    5. Context menu items
    6. Options page
    7. Bundled web pages
    8. Notifications
    9. Address bar suggestions
    10. Developer tools panels
  5. Concepts
    1. Using the JavaScript APIs
    2. Content scripts
    3. Match patterns
    4. Internationalization
    5. Content Security Policy
    6. Native messaging
  6. Porting
    1. Porting a Google Chrome extension
    2. Porting a legacy Firefox extension
    3. Embedded WebExtensions
    4. Comparison with the Add-on SDK
    5. Comparison with XUL/XPCOM extensions
    6. Chrome incompatibilities
    7. Differences between desktop and Android
  7. Firefox workflow
    1. Temporary Installation in Firefox
    2. Debugging
    3. Developing for Firefox for Android
    4. Getting started with web-ext
    5. web-ext command reference
    6. Extensions and the Add-on ID
    7. Publishing your extension
  8. JavaScript APIs
    1. Browser support for JavaScript APIs
    2. alarms
    3. bookmarks
    4. browserAction
    5. browsingData
    6. commands
    7. contextMenus
    8. contextualIdentities
    9. cookies
    10. devtools.inspectedWindow
    11. devtools.network
    12. devtools.panels
    13. downloads
    14. events
    15. extension
    16. extensionTypes
    17. history
    18. i18n
    19. identity
    20. idle
    21. management
    22. notifications
    23. omnibox
    24. pageAction
    25. permissions
    26. privacy
    27. proxy
    28. runtime
    29. sessions
    30. sidebarAction
    31. storage
    32. tabs
    33. topSites
    34. types
    35. webNavigation
    36. webRequest
    37. windows
  9. Manifest keys
    1. applications
    2. author
    3. background
    4. browser_action
    5. chrome_settings_overrides
    6. chrome_url_overrides
    7. commands
    8. content_scripts
    9. content_security_policy
    10. default_locale
    11. description
    12. developer
    13. devtools_page
    14. homepage_url
    15. icons
    16. incognito
    17. manifest_version
    18. name
    19. omnibox
    20. optional_permissions
    21. options_ui
    22. page_action
    23. permissions
    24. protocol_handlers
    25. short_name
    26. sidebar_action
    27. version
    28. web_accessible_resources
  10. Themes
  11. Publishing add-ons
  12. Guides
    1. Signing and distribution overview
    2. Submit an add-on
    3. Creating an appealing listing
    4. Review policies
    5. Developer agreement
    6. Featured add-ons
    7. Contact addons.mozilla.org
  13. Community and support
  14. Channels
    1. Add-ons blog
    2. Add-on forums
    3. Stack Overflow
    4. Development newsgroup
    5. IRC Channel
  15. Legacy add-ons
  16. Legacy technologies
    1. Add-on SDK
    2. Legacy Firefox for Android
    3. Bootstrapped extensions
    4. Overlay extensions