这篇翻译不完整。请帮忙从英语翻译这篇文章

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

它提供一组消息通信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()
Retrieves the Window object for the background page running inside the current add-on.
runtime.openOptionsPage()

Opens your add-ons's options page.

runtime.getManifest()
Gets the complete manifest.json file, serialized as an object.
runtime.getURL()
Given a relative path from the manifest.json to a resource packaged with the add-on, returns a fully-qualified URL.
runtime.setUninstallURL()
Sets a URL to be visited when the add-on is uninstalled.
runtime.reload()
Reloads the add-on.
runtime.requestUpdateCheck()
Checks for updates to this add-on.
runtime.connect()
Establishes a connection from a content script to the main add-on process, or from one add-on to a different add-on.
runtime.connectNative()
Connects the WebExtension to a native application on the user's computer.
runtime.sendMessage()
Sends a single message to event listeners within your add-on or a different add-on. Similar to runtime.connect but only sends a single message, with an optional response.
runtime.sendNativeMessage()
Sends a single message from a WebExtension to a native application.
runtime.getPlatformInfo()
Returns information about the current platform.
runtime.getBrowserInfo()
Returns information about the browser in which this add-on is installed.
runtime.getPackageDirectoryEntry()
Returns a DirectoryEntry for the package directory.

Events

runtime.onStartup
Fired when a profile that has this add-on installed first starts up. This event is not fired when an incognito profile is started.
runtime.onInstalled
Fired when the add-on is first installed, when the add-on 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 the add-on is unloaded. This gives the add-on an opportunity to do some cleanup.
runtime.onSuspendCanceled
Sent after runtime.onSuspend to indicate that the add-on won't be unloaded after all.
runtime.onUpdateAvailable
Fired when an update is available, but isn't installed immediately because the add-on is currently running.
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 with either an add-on process or a content script.
runtime.onConnectExternal
Fired when a connection is made with another add-on.
runtime.onMessage
Fired when a message is sent from either an add-on process or a content script.
runtime.onMessageExternal
Fired when a message is sent from another add-on. Cannot be used in a content script.
runtime.onRestartRequired
Fired when the device needs to be restarted.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox 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 15Firefox 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'.
Firefox Android Full support 48
OnRestartRequiredReasonChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
PlatformArchChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
PlatformInfoChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
PlatformNaclArchChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
PlatformOsChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
PortChrome Full support 26Edge Full support 15Firefox Full support 45Opera Full support 15Firefox Android Full support 48
RequestUpdateCheckStatusChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
connectChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Firefox Android Full support 48
connectNativeChrome Full support 29Edge Full support 15Firefox Full support 50Opera Full support 16Firefox 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 15Firefox 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 NoFirefox Android Full support 51
getManifestChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Firefox Android Full support 48
getPackageDirectoryEntryChrome Full support 29Edge No support NoFirefox No support NoOpera Full support 16Firefox Android No support No
getPlatformInfoChrome Full support 29Edge No support NoFirefox Full support 45Opera Full support 16Firefox Android Full support 48
getURLChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Firefox Android Full support 48
idChrome Full support 22Edge Full support 14Firefox Full support 45Opera Full support 15Firefox 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.
Firefox Android Full support 48
onBrowserUpdateAvailable
DeprecatedNon-standard
Chrome Full support 27Edge No support NoFirefox No support NoOpera Full support 15Firefox Android No support No
onConnectChrome Full support 26Edge Full support 14Firefox Full support 45Opera Full support 15Firefox Android Full support 48
onConnectExternalChrome Full support 26Edge No support NoFirefox Full support 54Opera Full support 15Firefox 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 15Firefox 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 15Firefox Android Full support 48
onMessageExternalChrome Full support 26Edge No support NoFirefox Full support 54Opera Full support 15Firefox Android Full support 54
onRestartRequiredChrome Full support 29Edge No support NoFirefox No support NoOpera Full support 16Firefox Android No support No
onStartupChrome Full support 23Edge No support NoFirefox Full support 52Opera Full support 15Firefox Android Full support 52
onSuspendChrome Full support 22Edge No support NoFirefox No support NoOpera Full support 15Firefox Android No support No
onSuspendCanceledChrome Full support 22Edge No support NoFirefox No support NoOpera Full support 15Firefox Android No support No
onUpdateAvailableChrome Full support 25Edge No support NoFirefox Full support 51Opera Full support 15Firefox Android Full support 51
openOptionsPageChrome Full support 42Edge No support NoFirefox Full support 48Opera Full support 29Firefox Android Full support 57
reloadChrome Full support 25Edge Full support 15Firefox Full support 51Opera Full support 15Firefox Android Full support 51
requestUpdateCheckChrome Full support 25Edge No support NoFirefox No support NoOpera Full support 15Firefox 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 15Firefox Android Full support 48
sendNativeMessageChrome Full support 29Edge Full support 15Firefox Full support 50Opera Full support 16Firefox Android No support No
setUninstallURLChrome Full support 41Edge Full support 15Firefox Full support 47Opera Full support 28Firefox Android Full support 48

Legend

Full support  
Full 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.

Chrome incompatibilities

None.

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.

文档标签和贡献者

此页面的贡献者: gogogoghost, WEKEYSHIT, wbamberg
最后编辑者: gogogoghost,