contextualIdentities.onCreated
当创建新的场景身份时触发事件。场景身份可以由扩展使用 contextualIdentities
API 创建,也可以由用户直接通过浏览器的用户界面创建。
语法
js
browser.contextualIdentities.onCreated.addListener(listener)
browser.contextualIdentities.onCreated.removeListener(listener)
browser.contextualIdentities.onCreated.hasListener(listener)
事件有三个函数:
addListener(listener)
-
添加一个监听器到这个事件。
removeListener(listener)
-
停止监听这个事件。
listener
参数是要移除的监听器。 hasListener(listener)
-
检查
listener
是否已注册为此事件的监听器。如果正在监听,则返回true
,否则返回false
。
addListener 语法
参数
listener
-
当事件发生时调用的函数。该函数接收以下参数:
changeInfo
-
object
。包含单个属性contextualIdentity
的对象,它是一个表示创建的身份的contextualIdentities.ContextualIdentity
对象。
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
onCreated |
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
function handleCreated(changeInfo) {
console.log(`已创建:${changeInfo.contextualIdentity.name}`);
}
browser.contextualIdentities.onCreated.addListener(handleCreated);