browser.createUserContext command
The browser.createUserContext command of the browser module creates a new user context in the browser.
Syntax
{
"method": "browser.createUserContext",
"params": {}
}
Parameters
Set params to an empty object ({}) or include any of the following optional fields:
acceptInsecureCertsOptional-
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
acceptInsecureCertssetting for this user context. proxyOptional-
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
proxysetting for this user context. unhandledPromptBehaviorOptional-
An object that specifies the default behavior when a user prompt (such as an
alert,confirm, orpromptdialog) is encountered within this user context. When set, it overrides the session-levelunhandledPromptBehaviorsetting 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 uniquely identifies the created user context.
Errors
unsupported operation-
acceptInsecureCertsistruebut the browser does not support accepting insecure TLS connections, orproxyis 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
| Specification |
|---|
| WebDriver BiDi> # command-browser-createUserContext> |
Browser compatibility
See also
session.newcommandbrowser.getUserContextscommandbrowser.removeUserContextcommand