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, theruntime.onMessage
event will be fired in each page, orruntime.onMessageExternal
, if a different extension. Note that extensions cannot send messages to content scripts using this method. To send messages to content scripts, usetabs.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 callruntime.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 ifruntime.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
Edge | Firefox | Chrome | Opera | |
---|---|---|---|---|
MessageSender | ? | 45.0 | Yes | 33 |
OnInstalledReason | ? | 45.0 | Yes | 33 |
OnRestartRequiredReason | ? | 45.0 | Yes | 33 |
PlatformArch | ? | 45.0 | Yes | 33 |
PlatformInfo | ? | 45.01 | Yes | 33 |
PlatformNaclArch | ? | 45.0 | Yes | 33 |
PlatformOs | ? | 45.0 | Yes | 33 |
Port | ? | 45.0 | Yes | 33 |
RequestUpdateCheckStatus | ? | 45.0 | Yes | 33 |
connect | ? | 45.0 | Yes | 33 |
connectNative | ? | No | Yes | 33 |
getBackgroundPage | ? | 45.0 | Yes | 33 |
getManifest | ? | 45.0 | Yes | 33 |
getPackageDirectoryEntry | ? | No | Yes | 33 |
getPlatformInfo | ? | 45.0 | Yes | 33 |
getURL | ? | 45.0 | Yes | 33 |
id | ? | 45.0 | Yes | 33 |
lastError | ? | 47.0 | Yes | 33 |
onBrowserUpdateAvailable | ? | No | Yes | 33 |
onConnect | ? | 45.0 | Yes | 33 |
onConnectExternal | ? | No | Yes | 33 |
onInstalled | ? | No | Yes | 33 |
onMessage | ? | 45.0 | Yes | 33 |
onMessageExternal | ? | No | Yes | 33 |
onRestartRequired | ? | No | Yes | 33 |
onStartup | ? | No | Yes | 33 |
onSuspend | ? | No | Yes | 33 |
onSuspendCanceled | ? | No | Yes | 33 |
onUpdateAvailable | ? | No | Yes | 33 |
openOptionsPage | ? | 48.0 | Yes | 33 |
reload | ? | No | Yes | 33 |
requestUpdateCheck | ? | No | Yes | 33 |
restart | ? | No | Yes | 33 |
sendMessage | ? | 45.0 | Yes | 33 |
sendNativeMessage | ? | No | Yes | 33 |
setUninstallURL | ? | 47.0 | Yes | 33 |
Firefox | |
---|---|
MessageSender | 48.0 |
OnInstalledReason | 48.0 |
OnRestartRequiredReason | 48.0 |
PlatformArch | 48.0 |
PlatformInfo | 48.02 |
PlatformNaclArch | 48.0 |
PlatformOs | 48.0 |
Port | 48.0 |
RequestUpdateCheckStatus | 48.0 |
connect | 48.0 |
connectNative | No |
getBackgroundPage | 48.0 |
getManifest | 48.0 |
getPackageDirectoryEntry | No |
getPlatformInfo | 48.0 |
getURL | 48.0 |
id | 48.0 |
lastError | 48.0 |
onBrowserUpdateAvailable | No |
onConnect | 48.0 |
onConnectExternal | No |
onInstalled | No |
onMessage | 48.0 |
onMessageExternal | No |
onRestartRequired | No |
onStartup | 48.0 |
onSuspend | No |
onSuspendCanceled | No |
onUpdateAvailable | No |
openOptionsPage | No |
reload | No |
requestUpdateCheck | No |
restart | No |
sendMessage | 48.0 |
sendNativeMessage | No |
setUninstallURL | 48.0 |
1. Firefox does not support nacl_arch.
2. Firefox does not support nacl_arch.
The "Chrome incompatibilities" section is included from https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities using the WebExtChromeCompat macro.
If you need to update this content, edit https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities, then shift-refresh this page to see your changes.
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
This API is based on Chromium's chrome.runtime
API. This documentation is derived from runtime.json
in the Chromium code.
// Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.