WebExtensions Examples

repository·main·Indexed 26 days ago

https://github.com/mdn/webextensions-examples

A collection of simple, complete, and installable example add-ons designed to demonstrate the use of various WebExtension APIs. These examples serve as starting points for building browser extensions for Firefox, Chrome, Edge, and Opera, covering patterns such as content script injection, sidebar creation, clipboard interaction, and the use of APIs like browser.storage.local, tabs, alarms, and bookmarks.

Tokens
18.5K
Snippets
26
Records
156
Agent score
88%

What's inside webextensions-examples

  1. Overview of the Emoji Substitution add-on

    main

    The Emoji Substitution add-on is a WebExtension designed to demonstrate how to use content scripts to manipulate web page content. It scans web pages for specific text patterns that describe emojis and replaces those words with the actual emoji characters.

    Important Limitation: This add-on injects JavaScript into web pages. Because of security restrictions, it will not function on the addons.mozilla.org domain.

  2. Overview of the runtime-examples extension

    main

    The runtime-examples extension demonstrates the use of various WebExtension runtime and notification APIs.

    Key features include:

    • Install Notifications: Triggers a notification immediately upon installation.
    • Dynamic Browser Action: Displays the time elapsed since the background page was last loaded (in minutes and seconds) directly on the browser action text.
    • Interactive Reload: Clicking the browser action triggers a reload of the background page and updates the displayed load time.
    • Manifest Versioning: Notifications display the current extension version by fetching it from the manifest.json file.
  3. Overview of the root-cert-stats extension

    main

    The root-cert-stats extension demonstrates how to monitor and collect statistics regarding trusted root certificates used during TLS connections.

    It consists of:

    • A background page that uses the webRequest.getSecurityInfo() API to record the subject name of each root certificate and the frequency of its use in establishing TLS connections.
    • A browser action popup that displays the collected statistics to the user.
  4. Overview of notify-link-clicks-i18n extension

    main
    The notify-link-clicks-i18n extension demonstrates how to inject content scripts into web pages to monitor user interactions and communicate with a background script. Specifically, it listens for link clicks and triggers a system notification containing the link's URL. This example is primarily used to illustrate internationalization (i18n) for extension names, descriptions, and notification content, supporting en-US, German, Dutch, and Japanese.
  5. Overview of the Image Reference Collector example

    main

    The 'Image Reference Collector' is a WebExtension example designed to demonstrate how to store and manipulate files within a WebExtension using the idb-file-storage library.

    Core Functionality:

    • Adds a context menu item targeting image elements on webpages.
    • Opens a window to preview and add images to a collection.
    • Allows users to save collections with a custom name.
    • Provides an extension page (opened via the browserAction) to navigate stored images.

    Key Technical Demonstrations:

    • Storing blobs in the add-on's IndexedDB storage.
    • Listing stored blobs (with optional filtering).
    • Converting stored blobs into blob URLs for display in the extension page.
    • Removing stored blobs from IndexedDB storage.