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 thatruntime.onInstalled is not the same asmanagement.onInstalled. Theruntime.onInstalled event is fired only for your extension. Thebrowser.management.onInstalled event is fired for any extensions.
In this article
Syntax
browser.runtime.onInstalled.addListener(listener)browser.runtime.onInstalled.removeListener(listener)browser.runtime.onInstalled.hasListener(listener)Events have three functions:
addListener(listener)Adds a listener to this event.
removeListener(listener)Stop listening to this event. The
listenerargument is the listener to remove.hasListener(listener)Checks whether a
listeneris registered for this event. Returnstrueif it is listening,falseotherwise.
addListener syntax
>Parameters
functionThe function called when this event occurs. The function is passed these arguments:
detailsAn object with the following properties:
idOptionalstring. The ID of the imported shared module extension that updated. This is present only if thereasonvalue isshared_module_update.previousVersionOptionalstring. The previous version of the extension just updated. This is only present if thereasonvalue isupdate.reasonA
runtime.OnInstalledReasonvalue, stating the reason that this event is being dispatched.temporaryboolean. True if the add-on was installed temporarily. For example, using the "about:debugging" page in Firefox or usingweb-ext run. False otherwise.
Examples
When the extension is installed, log the install reason and openhttps://example.com:
function handleInstalled(details) { console.log(details.reason); browser.tabs.create({ url: "https://example.com", });}browser.runtime.onInstalled.addListener(handleInstalled);Example extensions
Browser compatibility
Note:This API is based on Chromium'schrome.runtime API. This documentation is derived fromruntime.json in the Chromium code.