Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/runtime/oninstalled/index.md
6552 views
------{{AddonSidebar()}}
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 {{WebExtAPIRef("management.onInstalled")}}. The runtime.onInstalled event is fired only for your extension. The browser.management.onInstalled event is fired for any extensions.
Syntax
Events have three functions:
addListener(callback): 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
function: The callback function called when this event occurs. The function will be passed the following arguments:
details: An object with the following properties:
id{{optional_inline}}:
string. The ID of the imported shared module extension that updated. This is present only if thereasonvalue isshared_module_update.
previousVersion{{optional_inline}}:
string. The previous version of the extension just updated. This is only present if thereasonvalue isupdate.
reason: An {{WebExtAPIRef('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
{{Compat}}
Examples
When the extension is installed, log the install reason and open https://example.com:
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.runtimeAPI. This documentation is derived fromruntime.jsonin the Chromium code.