runtime

翻译不完整。 请帮助我们翻译这篇文章!

该模块提供关于附加组件以及运行环境的信息。

它提供一组消息通信API,允许你:

  • 在附加组件的不同模块间通信。
  • 和其它的附加组件通信。
  • 和native应用通信。

Types

runtime.Port
表示两个特定上下文之间的连接的一端,可用于交换消息。
runtime.MessageSender

包含有关消息或连接请求的发件人的信息。

runtime.PlatformOs
标识浏览器的操作系统。
runtime.PlatformArch
标识浏览器的处理器架构。
runtime.PlatformInfo
包含有关浏览器正在运行的平台的信息。
runtime.RequestUpdateCheckStatus
runtime.requestUpdateCheck() 的返回结果。
runtime.OnInstalledReason
runtime.onInstalled 事件被触发的原因。
runtime.OnRestartRequiredReason
runtime.onRestartRequired 事件被触发的原因。

Properties

runtime.lastError
当异步方法执行时发生了错误,它需要向其调用方报告时,该值会被设置。
runtime.id
当前扩展的ID。

Functions

runtime.getBackgroundPage()
取得当前扩展的后台页的 Window 对象。
runtime.openOptionsPage()

打开你的扩展的 选项页面

runtime.getManifest()
获得完整的 manifest.json 声明文件的序列化对象。
runtime.getURL()
给定某个打包在扩展中的资源的基于 manifest.json 相对路径,返回一个完整有效的 URL。
runtime.setUninstallURL()
指定一个此扩展被卸载后打开的 URL。
runtime.reload()
重新加载此扩展。
runtime.requestUpdateCheck()
检查此扩展的更新。
runtime.connect()
建立一个页面脚本到扩展主进程,或扩展主进程到页面脚本之间的通信连接。
runtime.connectNative()
建立一个浏览器扩展与用户电脑上的原生应用的通信连接。
runtime.sendMessage()
发送一条消息到此扩展或其他扩展的事件监听器,类似于  runtime.connect 但只能发送一条消息,以及可选的响应处理函数。
runtime.sendNativeMessage()
从扩展发送一条消息到原生应用。
runtime.getPlatformInfo()
返回当前所在平台的信息。
runtime.getBrowserInfo()
返回此扩展所在的浏览器的信息。
runtime.getPackageDirectoryEntry()
返回此扩展所在目录的 DirectoryEntry。

Events

runtime.onStartup
当一个拥有此扩展的账户第一次启动时触发,注意若处于隐私模式中则不会触发。
runtime.onInstalled
当扩展第一次安装,扩展更新,浏览器更新后触发。
runtime.onSuspend
当扩展将被停止前触发,使得扩展可以执行一些清理工作。
runtime.onSuspendCanceled
在此事件 runtime.onSuspend 后触发,表明扩展最终没有被停止。
runtime.onUpdateAvailable
当扩展更新可用时触发,注意若扩展运行中,更新不会马上被安装。
runtime.onBrowserUpdateAvailable
当浏览器更新可用时触发,注意浏览器需要重启才能安装更新。
runtime.onConnect
与扩展进程或页面脚本(content script)建立通信连接时触发。
runtime.onConnectExternal
与其他扩展建立通信连接时触发。
runtime.onMessage
当收到扩展进程或页面脚本(content script)的消息时触发。
runtime.onMessageExternal
当收到其他扩展的消息时触发,不能在页面脚本(content script)中使用。
runtime.onRestartRequired
当设备要重启时触发。

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaSafariFirefox for Android
MessageSenderChrome Full support 26Edge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes Before version 54, 'id' was the add-on's internal UUID, not the add-on ID.
Opera Full support 15Safari Full support 14Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Before version 54, 'id' was the add-on's internal UUID, not the add-on ID.
OnInstalledReasonChrome Full support Yes
Notes
Full support Yes
Notes
Notes Uses 'chrome_update' instead of 'browser_update'.
Edge Full support 14
Notes
Full support 14
Notes
Notes Only supports 'install' and 'update'.
Firefox Full support 45Opera Full support Yes
Notes
Full support Yes
Notes
Notes Uses 'chrome_update' instead of 'browser_update'.
Safari Full support 14
Notes
Full support 14
Notes
Notes Only supports 'install' and 'update'.
Firefox Android Full support 48
OnRestartRequiredReasonChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari No support NoFirefox Android Full support 48
PlatformArchChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari Full support 14Firefox Android Full support 48
PlatformInfoChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari Full support 14Firefox Android Full support 48
PlatformNaclArchChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari No support NoFirefox Android Full support 48
PlatformOsChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari Full support 14Firefox Android Full support 48
PortChrome Full support 26Edge Full support 15Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
RequestUpdateCheckStatusChrome Full support YesEdge Full support 79Firefox No support NoOpera Full support YesSafari No support NoFirefox Android No support No
connectChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
connectNativeChrome Full support 29Edge Full support 15Firefox Full support 50Opera Full support 16Safari Full support 14
Notes
Full support 14
Notes
Notes See the documentation on developer.apple.com about native messaging in Safari.
Firefox Android No support No
getBackgroundPageChrome Full support 22Edge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes If this is called from a page that is part of a private browsing window, such as a sidebar in a private window or a popup opened from a private window, then it will always return null.
Opera Full support 15Safari Full support 14Firefox Android Full support 48
Notes
Full support 48
Notes
Notes If this is called from a page that is part of a private browsing window, such as a sidebar in a private window or a popup opened from a private window, then it will always return null.
getBrowserInfoChrome No support NoEdge No support NoFirefox Full support 51Opera No support NoSafari No support NoFirefox Android Full support 51
getManifestChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
getPackageDirectoryEntryChrome Full support 29Edge Full support 79Firefox No support NoOpera Full support 16Safari No support NoFirefox Android No support No
getPlatformInfoChrome Full support 29Edge Full support 79Firefox Full support 45Opera Full support 16Safari Full support 14Firefox Android Full support 48
getURLChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
idChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
lastErrorChrome Full support Yes
Notes
Full support Yes
Notes
Notes lastError is not an Error object. Instead, it is a plain Object with the error text as the string value of the 'message' property.
Edge Full support 14Firefox Full support 47Opera Full support Yes
Notes
Full support Yes
Notes
Notes lastError is not an Error object. Instead, it is a plain Object with the error text as the string value of the 'message' property.
Safari Full support 14
Notes
Full support 14
Notes
Notes lastError is only set if a callback is used. Promise results that fail will be rejected with an Error object.
Firefox Android Full support 48
onBrowserUpdateAvailable
DeprecatedNon-standard
Chrome Full support 27Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
onConnectChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
onConnectExternalChrome Full support 26Edge Full support 79Firefox Full support 54Opera Full support 15Safari No support NoFirefox Android Full support 54
onInstalledChrome 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 15Safari Full support 14Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Before version 55, this event is not triggered for temporarily installed add-ons.
onMessageChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
onMessageExternalChrome Full support 26Edge Full support 79Firefox Full support 54Opera Full support 15Safari Full support 14Firefox Android Full support 54
onRestartRequiredChrome Full support 29Edge Full support 79Firefox No support NoOpera Full support 16Safari No support NoFirefox Android No support No
onStartupChrome Full support 23Edge Full support 79Firefox Full support 52Opera Full support 15Safari Full support 14Firefox Android Full support 52
onSuspendChrome Full support 22Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
onSuspendCanceledChrome Full support 22Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
onUpdateAvailableChrome Full support 25Edge Full support 79Firefox Full support 51Opera Full support 15Safari No support NoFirefox Android Full support 51
openOptionsPageChrome Full support 42Edge Full support 79Firefox Full support 48Opera Full support 29Safari Full support 14Firefox Android Full support 57
reloadChrome Full support 25Edge Full support 15Firefox Full support 51Opera Full support 15Safari Full support 14Firefox Android Full support 51
requestUpdateCheckChrome Full support 25Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
sendMessageChrome Full support 26Edge Full support 14
Notes
Full support 14
Notes
Notes `runtime.onMessage` listeners in extension views receive the messages they sent.
Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
sendNativeMessageChrome Full support 29Edge Full support 15Firefox Full support 50Opera Full support 16Safari Full support 14
Notes
Full support 14
Notes
Notes See the documentation on developer.apple.com about native messaging in Safari.
Firefox Android No support No
setUninstallURLChrome Full support 41Edge Full support 15Firefox Full support 47Opera Full support 28Safari Partial support 14
Notes
Partial support 14
Notes
Notes API exists, but has no effect.
Firefox Android Full support 48

Legend

Full support  
Full support
Partial support  
Partial support
No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaSafariFirefox for Android
MessageSenderChrome Full support 26Edge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes Before version 54, 'id' was the add-on's internal UUID, not the add-on ID.
Opera Full support 15Safari Full support 14Firefox Android Full support 48
Notes
Full support 48
Notes
Notes Before version 54, 'id' was the add-on's internal UUID, not the add-on ID.
OnInstalledReasonChrome Full support Yes
Notes
Full support Yes
Notes
Notes Uses 'chrome_update' instead of 'browser_update'.
Edge Full support 14
Notes
Full support 14
Notes
Notes Only supports 'install' and 'update'.
Firefox Full support 45Opera Full support Yes
Notes
Full support Yes
Notes
Notes Uses 'chrome_update' instead of 'browser_update'.
Safari Full support 14
Notes
Full support 14
Notes
Notes Only supports 'install' and 'update'.
Firefox Android Full support 48
OnRestartRequiredReasonChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari No support NoFirefox Android Full support 48
PlatformArchChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari Full support 14Firefox Android Full support 48
PlatformInfoChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari Full support 14Firefox Android Full support 48
PlatformNaclArchChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari No support NoFirefox Android Full support 48
PlatformOsChrome Full support YesEdge Full support 79Firefox Full support 45Opera Full support YesSafari Full support 14Firefox Android Full support 48
PortChrome Full support 26Edge Full support 15Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
RequestUpdateCheckStatusChrome Full support YesEdge Full support 79Firefox No support NoOpera Full support YesSafari No support NoFirefox Android No support No
connectChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
connectNativeChrome Full support 29Edge Full support 15Firefox Full support 50Opera Full support 16Safari Full support 14
Notes
Full support 14
Notes
Notes See the documentation on developer.apple.com about native messaging in Safari.
Firefox Android No support No
getBackgroundPageChrome Full support 22Edge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes If this is called from a page that is part of a private browsing window, such as a sidebar in a private window or a popup opened from a private window, then it will always return null.
Opera Full support 15Safari Full support 14Firefox Android Full support 48
Notes
Full support 48
Notes
Notes If this is called from a page that is part of a private browsing window, such as a sidebar in a private window or a popup opened from a private window, then it will always return null.
getBrowserInfoChrome No support NoEdge No support NoFirefox Full support 51Opera No support NoSafari No support NoFirefox Android Full support 51
getManifestChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
getPackageDirectoryEntryChrome Full support 29Edge Full support 79Firefox No support NoOpera Full support 16Safari No support NoFirefox Android No support No
getPlatformInfoChrome Full support 29Edge Full support 79Firefox Full support 45Opera Full support 16Safari Full support 14Firefox Android Full support 48
getURLChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
idChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
lastErrorChrome Full support Yes
Notes
Full support Yes
Notes
Notes lastError is not an Error object. Instead, it is a plain Object with the error text as the string value of the 'message' property.
Edge Full support 14Firefox Full support 47Opera Full support Yes
Notes
Full support Yes
Notes
Notes lastError is not an Error object. Instead, it is a plain Object with the error text as the string value of the 'message' property.
Safari Full support 14
Notes
Full support 14
Notes
Notes lastError is only set if a callback is used. Promise results that fail will be rejected with an Error object.
Firefox Android Full support 48
onBrowserUpdateAvailable
DeprecatedNon-standard
Chrome Full support 27Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
onConnectChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
onConnectExternalChrome Full support 26Edge Full support 79Firefox Full support 54Opera Full support 15Safari No support NoFirefox Android Full support 54
onInstalledChrome 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 15Safari Full support 14Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Before version 55, this event is not triggered for temporarily installed add-ons.
onMessageChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
onMessageExternalChrome Full support 26Edge Full support 79Firefox Full support 54Opera Full support 15Safari Full support 14Firefox Android Full support 54
onRestartRequiredChrome Full support 29Edge Full support 79Firefox No support NoOpera Full support 16Safari No support NoFirefox Android No support No
onStartupChrome Full support 23Edge Full support 79Firefox Full support 52Opera Full support 15Safari Full support 14Firefox Android Full support 52
onSuspendChrome Full support 22Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
onSuspendCanceledChrome Full support 22Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
onUpdateAvailableChrome Full support 25Edge Full support 79Firefox Full support 51Opera Full support 15Safari No support NoFirefox Android Full support 51
openOptionsPageChrome Full support 42Edge Full support 79Firefox Full support 48Opera Full support 29Safari Full support 14Firefox Android Full support 57
reloadChrome Full support 25Edge Full support 15Firefox Full support 51Opera Full support 15Safari Full support 14Firefox Android Full support 51
requestUpdateCheckChrome Full support 25Edge Full support 79Firefox No support NoOpera Full support 15Safari No support NoFirefox Android No support No
sendMessageChrome Full support 26Edge Full support 14
Notes
Full support 14
Notes
Notes `runtime.onMessage` listeners in extension views receive the messages they sent.
Firefox Full support 45Opera Full support 15Safari Full support 14Firefox Android Full support 48
sendNativeMessageChrome Full support 29Edge Full support 15Firefox Full support 50Opera Full support 16Safari Full support 14
Notes
Full support 14
Notes
Notes See the documentation on developer.apple.com about native messaging in Safari.
Firefox Android No support No
setUninstallURLChrome Full support 41Edge Full support 15Firefox Full support 47Opera Full support 28Safari Partial support 14
Notes
Partial support 14
Notes
Notes API exists, but has no effect.
Firefox Android Full support 48

Legend

Full support  
Full support
Partial support  
Partial support
No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.

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.