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);

浏览器兼容性