runtime

This module provides information about your add-on and the environment it's running in. It also provides messaging APIs enabling you to: communicate between different parts of your add-on, communicate with other add-ons, and communicate with native applications.

Types

runtime.Port
Provides a dedicated messaging channel between two specific endpoints.
runtime.MessageSender

Contains information about the sender of a message or connection request.

runtime.PlatformOs
Identifies the browser's operating system.
runtime.PlatformArch
Identifies the browser's processor architecture.
runtime.PlatformInfo
Contains information about the platform the browser is running on.
runtime.RequestUpdateCheckStatus
Result of a call to runtime.requestUpdateCheck().
runtime.OnInstalledReason
The reason that the runtime.onInstalled event is being dispatched.
runtime.OnRestartRequiredReason
The reason that the runtime.onRestartRequired event is being dispatched.

Properties

runtime.lastError
This value is set when an asynchronous function has an error condition that it needs to report to its caller.
runtime.id
The ID of the add-on.

Functions

runtime.getBackgroundPage()
Retrieves the Window object for the background page running inside the current add-on.
runtime.openOptionsPage()

Open your add-ons's options page.

runtime.getManifest()
Get the complete manifest.json file, serialized to an object.
runtime.getURL()
Given a relative path from the manifest.json to a resource packaged with the add-on, return a fully-qualified URL.
runtime.setUninstallURL()
Sets the URL to be visited upon uninstallation. This may be used to clean up server-side data, do analytics, and implement surveys. Maximum 255 characters.
runtime.reload()
Reloads the add-on.
runtime.requestUpdateCheck()
Requests an update check for this add-on.
runtime.restart()
Restart the device when the app runs in kiosk mode. Otherwise, it's no-op.
runtime.connect()
Attempts to connect listeners within an add-on (such as the background page), or other extensions. Use this to connect a content script to the main add-on process, or to connect to other add-ons. Note that this does not connect to any listeners in a content script. Extensions may connect to content scripts embedded in tabs via tabs.connect.
runtime.connectNative()
Connects to a native application in the host machine.
runtime.sendMessage()
Sends a single message to event listeners within your extension/app or a different extension/app. Similar to runtime.connect but only sends a single message, with an optional response. If sending to your extension, the runtime.onMessage event will be fired in each page, or runtime.onMessageExternal, if a different extension. Note that extensions cannot send messages to content scripts using this method. To send messages to content scripts, use tabs.sendMessage.
runtime.sendNativeMessage()
Send a single message to a native application.
runtime.getPlatformInfo()
Returns information about the current platform.
runtime.getPackageDirectoryEntry()
Returns a DirectoryEntry for the package directory.

Events

runtime.onStartup
Fired when a profile that has this extension installed first starts up. This event is not fired when an incognito profile is started, even if this extension is operating in 'split' incognito mode.
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.
runtime.onSuspend
Sent to the event page just before it is unloaded. This gives the extension opportunity to do some clean up. Note that since the page is unloading, any asynchronous operations started while handling this event are not guaranteed to complete. If more activity for the event page occurs before it gets unloaded the onSuspendCanceled event will be sent and the page won't be unloaded.
runtime.onSuspendCanceled
Sent after onSuspend to indicate that the app won't be unloaded after all.
runtime.onUpdateAvailable
Fired when an update is available, but isn't installed immediately because the app is currently running. If you do nothing, the update will be installed the next time the background page gets unloaded, if you want it to be installed sooner you can explicitly call runtime.reload. If your extension is using a persistent background page, the background page of course never gets unloaded, so unless you call runtime.reload manually in response to this event the update will not get installed until the next time the browser itself restarts. If no handlers are listening for this event, and your extension has a persistent background page, it behaves as if runtime.reload is called in response to this event.
runtime.onBrowserUpdateAvailable
Fired when an update for the browser is available, but isn't installed immediately because a browser restart is required.
runtime.onConnect
Fired when a connection is made from either an extension process or a content script.
runtime.onConnectExternal
Fired when a connection is made from another extension.
runtime.onMessage
Fired when a message is sent from either an extension process or a content script.
runtime.onMessageExternal
Fired when a message is sent from another extension/app. Cannot be used in a content script.
runtime.onRestartRequired
Fired when an app or the device that it runs on needs to be restarted. The app should close all its windows at its earliest convenient time to let the restart to happen. If the app does nothing, a restart will be enforced after a 24-hour grace period has passed. Currently, this event is only fired for Chrome OS kiosk apps.

Browser compatibility

EdgeFirefoxChromeOpera
MessageSender?45.0Yes33
OnInstalledReason?45.0Yes33
OnRestartRequiredReason?45.0Yes33
PlatformArch?45.0Yes33
PlatformInfo?45.01Yes33
PlatformNaclArch?45.0Yes33
PlatformOs?45.0Yes33
Port?45.0Yes33
RequestUpdateCheckStatus?45.0Yes33
connect?45.0Yes33
connectNative?NoYes33
getBackgroundPage?45.0Yes33
getManifest?45.0Yes33
getPackageDirectoryEntry?NoYes33
getPlatformInfo?45.0Yes33
getURL?45.0Yes33
id?45.0Yes33
lastError?47.0Yes33
onBrowserUpdateAvailable?NoYes33
onConnect?45.0Yes33
onConnectExternal?NoYes33
onInstalled?NoYes33
onMessage?45.0Yes33
onMessageExternal?NoYes33
onRestartRequired?NoYes33
onStartup?NoYes33
onSuspend?NoYes33
onSuspendCanceled?NoYes33
onUpdateAvailable?NoYes33
openOptionsPage?48.0Yes33
reload?NoYes33
requestUpdateCheck?NoYes33
restart?NoYes33
sendMessage?45.0Yes33
sendNativeMessage?NoYes33
setUninstallURL?47.0Yes33
Firefox
MessageSender48.0
OnInstalledReason48.0
OnRestartRequiredReason48.0
PlatformArch48.0
PlatformInfo48.02
PlatformNaclArch48.0
PlatformOs48.0
Port48.0
RequestUpdateCheckStatus48.0
connect48.0
connectNativeNo
getBackgroundPage48.0
getManifest48.0
getPackageDirectoryEntryNo
getPlatformInfo48.0
getURL48.0
id48.0
lastError48.0
onBrowserUpdateAvailableNo
onConnect48.0
onConnectExternalNo
onInstalledNo
onMessage48.0
onMessageExternalNo
onRestartRequiredNo
onStartup48.0
onSuspendNo
onSuspendCanceledNo
onUpdateAvailableNo
openOptionsPageNo
reloadNo
requestUpdateCheckNo
restartNo
sendMessage48.0
sendNativeMessageNo
setUninstallURL48.0

1. Firefox does not support nacl_arch.
2. Firefox does not support nacl_arch.

Chrome incompatibilities

  • Firefox does not support:
    • connectNative()
    • getPackageDirectoryEntry()
    • openOptionsPage()
    • reload()
    • requestUpdateCheck()
    • restart()
    • sendNativeMessage()
    • onBrowserUpdateAvailable
    • onConnectExternal
    • onInstalled
    • onMessageExternal
    • onRestartRequired
    • onStartup
    • onSuspend
    • onSuspendCanceled
    • onUpdateAvailable

Example add-ons

Acknowledgements

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

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,