management.onInstalled()
当有附加组件被安装时触发。
此 API 需要“management”API 权限。
语法
js
browser.management.onInstalled.addListener(listener)
browser.management.onInstalled.removeListener(listener)
browser.management.onInstalled.hasListener(listener)
事件有三个函数:
addListener(listener)
-
向此事件添加监听器。
removeListener(listener)
-
停止监听此事件。
listener
参数是要移除的监听器。 hasListener(listener)
-
检查是否已为此事件注册了
listener
。如果正在监听,则返回true
,否则返回false
。
addListener 语法
参数
listener
-
在此事件发生时调用的函数。此函数接收以下参数:
info
-
ExtensionInfo
,关于已安装的附加组件的信息。
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
onInstalled |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
示例
打印被安装的附加组件的名称:
js
browser.management.onInstalled.addListener((info) => {
console.log(`${info.name} 被安装`);
});
备注:
该 API 基于 Chromium 的 chrome.management
API。本文衍生自 Chromium 代码中的 management.json
。