runtime.onInstalled

Fired when the extension is first installed, when the extension is updated to a new version, and when the browser is updated to a new version.

Note that runtime.onInstalled is not the same as management.onInstalled. The runtime.onInstalled event is fired only for your extension. The browser.management.onInstalled event is fired for any extensions.

Syntax

browser.runtime.onInstalled.addListener(listener)
browser.runtime.onInstalled.removeListener(listener)
browser.runtime.onInstalled.hasListener(listener)

Events have three functions:

addListener(callback)
Adds a listener to this event.
removeListener(listener)
Stop listening to this event. The listener argument is the listener to remove.
hasListener(listener)
Checks whether a listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax

Parameters

function

The callback function called when this event occurs. The function will be passed the following arguments:

details
An object with the following properties:
idOptional
string. The ID of the imported shared module extension that updated. This is present only if the reason value is shared_module_update.
previousVersionOptional
string. The previous version of the extension just updated. This is only present if the reason value is update.
reason
An runtime.OnInstalledReason value, stating the reason that this event is being dispatched.
temporary
boolean. True if the add-on was installed temporarily. For example, using the "about:debugging" page in Firefox or using web-ext run. False otherwise.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
Basic supportChrome Full support 22Edge Full support 14Firefox Full support 52
Notes
Full support 52
Notes
Notes Before version 55, this event is not triggered for temporarily installed add-ons.
Opera Full support 15Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Before version 55, this event is not triggered for temporarily installed add-ons.
details.idChrome Full support 22Edge Full support 14Firefox No support NoOpera Full support 15Firefox Android No support No
details.previousVersionChrome Full support 22Edge Full support 14Firefox Full support 55Opera Full support 15Firefox Android Full support 55
details.reasonChrome Full support 22Edge Full support 14Firefox Full support 52Opera Full support 15Firefox Android Full support 52
details.temporaryChrome No support NoEdge No support NoFirefox Full support 55Opera No support NoFirefox Android Full support 55

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

Examples

When the extension is installed, log the install reason and open https://www.reddit.com/r/CatGifs/:

function handleInstalled(details) {
  console.log(details.reason);
  browser.tabs.create({
    url: "http://chilloutandwatchsomecatgifs.com/"
  });
}

browser.runtime.onInstalled.addListener(handleInstalled);

Example extensions

Acknowledgements

This API is based on Chromium's chrome.runtime API. This documentation is derived from runtime.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

Last updated by: david_ross,