大网数据广告活动
Web 标准与前端开发

`browser.getUserContexts` command

· 52CE 我爱测

The `browser.getUserContexts` command of the `browser` module returns a list of all current user contexts in the browser.

The browser.getUserContexts command of the browser module returns a list of all current user contexts in the browser.

Syntax

{
  "method": "browser.getUserContexts",
  "params": {}
}

Parameters

None. However, you must include the params field and set it to an empty object ({}).

Return value

The following field in the result object of the response describes the user contexts in the browser:

  • userContexts
    • : An array of one or more objects, each representing a user context. Each object has the following field:
      • userContext
        • : A string that contains the ID that uniquely identifies the user context. The default user context has the value "default"; it always exists and cannot be removed, so the array is never empty.

Examples

Getting a list of user contexts

With a WebDriver BiDi connection and an active session, send the following message to get a list of all user contexts:

{
  "id": 1,
  "method": "browser.getUserContexts",
  "params": {}
}

When only the default user context exists, the browser responds as follows:

{
  "id": 1,
  "type": "success",
  "result": {
    "userContexts": [
      {
        "userContext": "default"
      }
    ]
  }
}

Getting a list of user contexts after creating additional ones

After creating a few user contexts with browser.createUserContext, send the following message to list all of them:

{
  "id": 2,
  "method": "browser.getUserContexts",
  "params": {}
}

The browser responds with all user contexts, including the default one, as follows:

{
  "id": 2,
  "type": "success",
  "result": {
    "userContexts": [
      {
        "userContext": "default"
      },
      {
        "userContext": "4e4b1f6d-3f1a-4b2e-9f8c-1a2b3c4d5e6f"
      },
      {
        "userContext": "7d9e2a1b-5c3f-4e6d-8a7b-2c1d0e9f8a7b"
      }
    ]
  }
}

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。