runtime

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

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

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

Types

runtime.Port (en-US)

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

runtime.MessageSender (en-US)

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

runtime.PlatformOs

标识浏览器的操作系统。

runtime.PlatformArch

标识浏览器的处理器架构。

runtime.PlatformInfo (en-US)

包含有关浏览器正在运行的平台的信息。

runtime.RequestUpdateCheckStatus (en-US)

runtime.requestUpdateCheck() (en-US) 的返回结果。

runtime.OnInstalledReason (en-US)

runtime.onInstalled (en-US) 事件被触发的原因。

runtime.OnRestartRequiredReason (en-US)

runtime.onRestartRequired (en-US) 事件被触发的原因。

Properties

runtime.lastError (en-US)

当异步方法执行时发生了错误,它需要向其调用方报告时,该值会被设置。

runtime.id (en-US)

当前扩展的 ID。

Functions

runtime.getBackgroundPage() (en-US)

取得当前扩展的后台页的 Window 对象。

runtime.openOptionsPage()

打开你的扩展的 选项页面

runtime.getManifest()

获得完整的 manifest.json 声明文件的序列化对象。

runtime.getURL() (en-US)

给定某个打包在扩展中的资源的基于 manifest.json 相对路径,返回一个完整有效的 URL。

runtime.setUninstallURL() (en-US)

指定一个此扩展被卸载后打开的 URL。

runtime.reload() (en-US)

重新加载此扩展。

runtime.requestUpdateCheck() (en-US)

检查此扩展的更新。

runtime.connect() (en-US)

建立一个页面脚本到扩展主进程,或扩展主进程到页面脚本之间的通信连接。

runtime.connectNative()

建立一个浏览器扩展与用户电脑上的原生应用的通信连接。

runtime.sendMessage()

发送一条消息到此扩展或其他扩展的事件监听器,类似于 runtime.connect (en-US) 但只能发送一条消息,以及可选的响应处理函数。

runtime.sendNativeMessage()

从扩展发送一条消息到原生应用。

runtime.getPlatformInfo() (en-US)

返回当前所在平台的信息。

runtime.getBrowserInfo() (en-US)

返回此扩展所在的浏览器的信息。

runtime.getPackageDirectoryEntry() (en-US)

返回此扩展所在目录的 DirectoryEntry。

Events

runtime.onStartup (en-US)

当一个拥有此扩展的账户第一次启动时触发,注意若处于隐私模式中则不会触发。

runtime.onInstalled (en-US)

当扩展第一次安装,扩展更新,浏览器更新后触发。

runtime.onSuspend (en-US)

当扩展将被停止前触发,使得扩展可以执行一些清理工作。

runtime.onSuspendCanceled (en-US)

在此事件 runtime.onSuspend (en-US) 后触发,表明扩展最终没有被停止。

runtime.onUpdateAvailable (en-US)

当扩展更新可用时触发,注意若扩展运行中,更新不会马上被安装。

runtime.onBrowserUpdateAvailable (en-US)

当浏览器更新可用时触发,注意浏览器需要重启才能安装更新。

runtime.onConnect

与扩展进程或页面脚本(content script)建立通信连接时触发。

runtime.onConnectExternal (en-US)

与其他扩展建立通信连接时触发。

runtime.onMessage (en-US)

当收到扩展进程或页面脚本(content script)的消息时触发。

runtime.onMessageExternal (en-US)

当收到其他扩展的消息时触发,不能在页面脚本(content script)中使用。

runtime.onRestartRequired (en-US)

当设备要重启时触发。

Browser compatibility

BCD tables only load in the browser

Example extensions

备注: 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.