extension

有关插件的工具;获取你的插件的资源包的 URL;获取你的插件页面的 Window 对象;获取各种设置的值。

备注: 该模块中的消息 API 被弃用,取而代之的是 runtime 模块中相应的 API。

类型

extension.ViewType

用于指定要获取的视图类型的字符串。

属性

extension.lastError 已弃用

如果异步扩展 API 中出现错误,将在回调的调用中将该属性设置为那一错误。若没有发生错误,lastError 将为 undefined

extension.inIncognitoContext

对在隐身模式标签中运行的内容脚本、在隐身模式进程中运行的扩展页面返回 true。(仅适用于 incognito_behavior 取值为“split”的扩展。)

函数

extension.getBackgroundPage()

返回当前扩展内运行的后台页面的 Window 对象。如果扩展不存在后台页面,则返回 null

extension.getExtensionTabs() 已弃用

返回当前扩展内运行的每个标签的 JavaScript Window 对象的数组。

extension.getURL() 已弃用

将扩展安装目录内的相对路径转换为完全限定的 URL。

extension.getViews()

返回当前扩展内运行的每个页面的 Window 对象的数组。

extension.isAllowedIncognitoAccess()

获取扩展对隐身模式的访问权限的状态(由用户控制的“允许在隐身模式中”复选框确定)。

extension.isAllowedFileSchemeAccess()

获取扩展对 file:// 协议的访问权限的状态(由用户控制的“允许访问文件 URL”复选框确定)。

extension.sendRequest() 已弃用

发送单一请求到扩展中的其他监听器。

extension.setUpdateUrlData()

设置扩展的更新 URL 中使用的 ap CGI 参数的值。对于托管在浏览器供应商商店中的扩展,此值将被忽略。

事件

extension.onRequest 已弃用

当从扩展进程或内容脚本发送请求时触发。

extension.onRequestExternal 已弃用

当从另一个扩展发送请求时触发。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
extension
ViewType
ViewType.sidebar
getBackgroundPage
getExtensionTabs
getURL
getViews
getViews.windowId
inIncognitoContext
isAllowedFileSchemeAccess
isAllowedIncognitoAccess
lastError
onRequest
onRequestExternal
sendRequest
setUpdateUrlData

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Uses a non-standard name.
Has more compatibility info.

示例扩展

备注: 此 API 基于 Chromium 的 chrome.extension API。该文档衍生自 Chromium 代码中的 extension.json