export-helpers

What it does

This extension demonstrates how to use export helpers in Firefox to share JavaScript objects defined in content scripts with scripts loaded by web pages.

How it works

This example is in two parts:

The extension

The extension loads a content script into the page at: https://mdn.github.io/webextensions-examples/export-helpers.html. The content script:

In the implementation of notify(), the content script sends a message to the extension’s background script: when the background script gets the messages, it displays a notification.

The page

The page is just a normal web page. It contains two buttons and loads a script. The script:

These items are available in the page’s scope because the content script exported them.

How to use it

To see the extension in action:

  1. install the extension
  2. visit https://mdn.github.io/webextensions-examples/export-helpers.html
  3. click one of the buttons in the page. You should see a notification from the extension.