contextualIdentities.update()

更新指定 Cookie 儲存 ID 的上下文身份的屬性。

這是一個非同步函式,返回一個 Promise

語法

js
let createContext = browser.contextualIdentities.update(
  cookieStoreId,           // string
  details                  // object
)

引數

cookieStoreId

string。此上下文身份的 Cookie 儲存的 ID。由於每個上下文身份都有自己的 Cookie 儲存,因此此 ID 也用作上下文身份本身的識別符號。

details

object。一個包含您希望更改的屬性的新值的物件。它可能包含以下任何屬性:

name 可選

string。身份的新名稱。這將在瀏覽器 UI 中顯示,使使用者能夠在此身份下開啟新選項卡。它還將顯示在此身份所屬選項卡 URL 欄中。

color 可選

string。身份的新顏色。這將用於突出顯示此身份所屬的選項卡。您可以提供以下任何值:

  • "blue"
  • "turquoise"
  • "green"
  • "yellow"
  • "orange"
  • "red"
  • "pink"
  • "purple"
  • "toolbar"
icon 可選

string。身份的新圖示。您可以提供以下任何值:

  • "fingerprint"
  • "briefcase"
  • "dollar"
  • "cart"
  • "circle"
  • "gift"
  • "vacation"
  • "food"
  • "fruit"
  • "pet"
  • "tree"
  • "chill"
  • "fence"

返回值

一個 Promise,它將以一個描述更新後的身份的 ContextualIdentity 物件 fulfilled。如果找不到該身份或上下文身份功能未啟用,則 Promise 將被 rejected。

示例

此示例更新 ID 為 "firefox-container-1" 的上下文身份,為其設定新的名稱、顏色和圖示。

js
function onUpdated(context) {
  console.log(`New identity's name: ${context.name}.`);
}

function onError(e) {
  console.error(e);
}

browser.contextualIdentities
  .update("firefox-container-1", {
    name: "my-thing",
    color: "purple",
    icon: "briefcase",
  })
  .then(onUpdated, onError);

瀏覽器相容性