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 語法

引數

監聽器

當此事件發生時呼叫的函式。該函式將傳遞此引數

changeInfo

object。一個包含單個屬性 contextualIdentity 的物件,該屬性是 contextualIdentities.ContextualIdentity 物件,代表已建立的標識。

示例

js
function handleCreated(changeInfo) {
  console.log(`Created: ${changeInfo.contextualIdentity.name}`);
}

browser.contextualIdentities.onCreated.addListener(handleCreated);

瀏覽器相容性