What is an add-on ID?
The add-on ID is used to uniquely identify each extension and in turn that ID is used to link an extension to certain features of the WebExtension APIs. These features are:
storage.managed
—identifies data as belonging to the extension by its add-on ID.storage.sync
—identifies data as belonging to the extension by its add-on ID.identity.getRedirectURL
—the redirect URL includes the extension's add-on ID.- Native messaging—the native app identifies extensions that can communicate with it by their add-on ID.
pkcs11
—the PKCS #11 module identifies extensions that can communicate with it by their add-on ID.runtime.onMessageExternal
—an extension sends messages to another extension using its add-on ID as the address.runtime.onConnectExternal
—an extension requests a connection with an extension by the other extension's add-on ID.browserAction
—the saved position of the button is identified as belonging to the extension based on its add-on ID.
An extension can be assigned an add-on ID using themanifest.json
filebrowser_specific_settings
key.
"browser_specific_settings":{"gecko":{"id":"addon@example.com"}}
If the extension doesn't have an add-on ID defined with thebrowser_specific_settings
key, it gets an add-on ID through one of the following:
- If the extension is submitted AMO and signed, it's given an ID when it's signed.
- If the extension is loaded using Load Temporary Add-on in
about:debugging
it's assigned a temporary add-on ID.
You'll notice an additional ID in the image above, the Internal UUID. This is a unique identifier given to the extension on installation. It's used to define the storage location for resources included in the extension and identify an extension's data inwindow.localStorage orindexedDB. However, you don't need to know its value. Its use inwindow.localStorage
orindexedDB
is transparent and to access resources included in the extension you useruntime.getURL
, which returns the path to the resources. And, because it's unique to each installation, it doesn't provide an ID that can be relied upon for other purposes.
What is a Firefox profile?
Data that defines how the user has configured Firefox, along with information generated as they browse the web such as history and cookies, is stored in a special folder, called aprofile. In addition to cookies, the profile holds local storage and other profile related content.
Extension behavior in Firefox
When you develop an extension, assuming you've not defined an add-on ID using thebrowser_specific_settings
key, the default behavior in Firefox is as follows:
- when using the Load Temporary Add-on feature in
about:debugging
your extension is assigned a new add-on ID each time you load it. - when using web-ext, in addition to getting a new add-on ID each time you launch an extension it's also launched into a new profile.
- when a temporarily loaded extension is unloaded, local storage, such as that used by
storage.local
,window.localStorage
, andindexedDB
, is removed. - when you stop Firefox, any temporarily loaded extensions are unloaded so aren't available when Firefox restarts. This includes extensions loaded with Load Temporary Add-on in
about:debugging
and web-ext.
The consequences of this behavior, when reloading an extension, is that:
- any data in local or sync storage is lost.
- any redirect URL becomes invalid.
- the extension will no longer be able to communicate with native apps or a PKCS #11 module.
- it will no longer be possible to send messages or create connections between extensions.
- you cannot test how the extension will behave if Firefox is stopped and restarted.
browserAction
positions are not carried over.
What do I do to ensure I can test my extension?
To get your extension to behave like a signed extension during development testing, use the following techniques:
to make sure an extension can use add-on ID dependent features between reloads, such as local storage or native application communication:
- set an add-on ID using the
browser_specific_settings
key in the extension'smanifest.json
. - when using web-ext, make sure you use the same profile.
- set an add-on ID using the
to ensure you use the same profile for multiple tests of an extension when using web-ext:
- optionally, useProfile Manager to create a new Firefox profile.
- find the path to your new profile or the default Firefox profile by following the instructions inHow do I find my profile?
- add the Firefox profile path to the
web-ext run
command as follows:web-ext run --firefox-profile [A PATH TO A FIREFOX PROFILE] --keep-profile-changes
to preserve
storage.local
data, access towindow.localStorage
orindexedDB
data when removing a temporary add-on (such as between browser restarts):- go to
about:config
and set bothextensions.webextensions.keepStorageOnUninstall
andextensions.webextensions.keepUuidOnUninstall
totrue
.
- go to
to test restart behavior:
- set an add-on ID using the
browser_specific_settings
key in the extension'smanifest.json
. - install theNightly orDeveloper editions of Firefox. Note: You can also useunbranded Beta and Release builds.
- go to
about:config
and setxpinstall.signatures.required
tofalse
. - package your extension into a ZIP fileusing web-ext or byzipping it manually.
- install your extension using Install Add-on From File in the Add-on manager (
about:addons
).
Note: Remember you'll need to reload your extension each time you change it.
Note: If you don't set the add-on ID, when you load the extension you get an error like this:
with a matching error in the browser console.
- set an add-on ID using the
Tags: add-on beginner development extensions how-to intermediate testing webextensions
Contributors: freaktechnik Rob--W rebloor tophf Dietrich
Last update: rebloor
Up Next
Develop
Test permission requests
Develop