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
Loading…
示例扩展
- beastify
- content-script-register
- cookie-bg-picker
- devtools-panels
- export-helpers
- favourite-colour
- find-across-tabs
- imagify
- menu-demo
- mocha-client-tests
- native-messaging
- notify-link-clicks-i18n
- permissions
- runtime-examples
- store-collected-images
- user-script-register
- userScripts-mv3
- webpack-modules
备注:
This API is based on Chromium's chrome.runtime API. This documentation is derived from runtime.json in the Chromium code.