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

`browser.createUserContext` command

· 52CE 我爱测

The `browser.createUserContext` command of the `browser` module creates a new user context in the browser.

The browser.createUserContext command of the browser module creates a new user context in the browser.

Syntax

/* Without optional parameters */
{
  "method": "browser.createUserContext",
  "params": {}
}

/* With optional parameters */
{
  "method": "browser.createUserContext",
  "params": {
    "acceptInsecureCerts": true,
    "proxy": {
      "proxyType": "manual",
      "httpProxy": "127.0.0.1:80"
    },
    "unhandledPromptBehavior": {
      "default": "accept"
    }
  }
}

Parameters

Set params to an empty object ({}) or include any of the following optional fields:

  • acceptInsecureCerts
    • : A boolean that controls whether untrusted TLS certificates (for example, self-signed or expired) are accepted within this user context. When set, it overrides the session-level acceptInsecureCerts setting for this user context.
  • proxy
    • : An object that specifies the proxy configuration the browser should use for network requests within this user context. When set, it overrides the session-level proxy setting for this user context.
  • unhandledPromptBehavior
    • : An object that specifies the default behavior when a user prompt (such as an alert, confirm, or prompt dialog) is encountered within this user context. When set, it overrides the session-level unhandledPromptBehavior setting for this user context.

[!NOTE] When a parameter is set, it applies to all existing and future tabs within this user context.

Return value

The following field in the result object of the response describes the created user context:

  • userContext
    • : A string that contains the ID that uniquely identifies the created user context.

Errors

  • invalid argument
    • : A required parameter is missing or has an invalid type.
  • unsupported operation
    • : acceptInsecureCerts is true but the browser does not support accepting insecure TLS connections, or proxy is specified but the browser cannot configure proxy settings for this user context or cannot apply the given proxy configuration.

Examples

Creating a user context with default settings

With a WebDriver BiDi connection and an active session, send the following message to create a user context:

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

The browser responds with a successful user context creation as follows:

{
  "id": 1,
  "type": "success",
  "result": {
    "userContext": "4e4b1f6d-3f1a-4b2e-9f8c-1a2b3c4d5e6f"
  }
}

Creating a user context with a proxy

Send the following message to create a user context that routes network requests through a proxy:

{
  "id": 2,
  "method": "browser.createUserContext",
  "params": {
    "proxy": {
      "proxyType": "manual",
      "httpProxy": "127.0.0.1:80"
    }
  }
}

The browser responds with a successful user context creation as follows:

{
  "id": 2,
  "type": "success",
  "result": {
    "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

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

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