Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: browser.close command
short-title: browser.close
slug: Web/WebDriver/Reference/BiDi/Modules/browser/close
page-type: webdriver-command
browser-compat: webdriver.bidi.browser.close
sidebar: webdriver
---

The `browser.close` [command](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules#commands) of the [`browser`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser) module closes the browser and ends all active WebDriver sessions. Tabs are closed without running [`beforeunload`](/en-US/docs/Web/API/Window/beforeunload_event) event handler functions. The response is sent before the WebSocket connection is closed.

## Syntax

```json-nolint
{
"method": "browser.close",
"params": {}
}
```

### Parameters

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

### Return value

The `result` field in the response is an empty object (`{}`).

### Errors

- `unable to close browser`
- : There are other active WebDriver sessions open at the time the command is sent.
Browsers may return this error before continuing to close.

## Examples

### Closing the browser

With a [WebDriver BiDi connection](/en-US/docs/Web/WebDriver/How_to/Create_BiDi_connection) and an [active session](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new), send the following message to close the browser:

```json
{
"id": 1,
"method": "browser.close",
"params": {}
}
```

Before closing, the browser responds successfully as shown here:

```json
{
"id": 1,
"type": "success",
"result": {}
}
```

After the response, the WebSocket connection closes as the browser shuts down.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new) command
- [`session.end`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/end) command
- [`browser.createUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/createUserContext) command
- [`browser.getUserContexts`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/getUserContexts) command
- [`browser.removeUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/removeUserContext) command
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: browser.createUserContext command
short-title: browser.createUserContext
slug: Web/WebDriver/Reference/BiDi/Modules/browser/createUserContext
page-type: webdriver-command
browser-compat: webdriver.bidi.browser.createUserContext
sidebar: webdriver
---

The `browser.createUserContext` [command](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules#commands) of the [`browser`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser) module creates a new [user context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser#user_contexts) in the browser.

## Syntax

```json-nolint
{
"method": "browser.createUserContext",
"params": {}
}
```

### Parameters

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

- [`acceptInsecureCerts`](/en-US/docs/Web/WebDriver/Reference/Capabilities/acceptInsecureCerts) {{optional_inline}}
- : 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](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new#acceptinsecurecerts) `acceptInsecureCerts` setting for this user context.
- `proxy` {{optional_inline}}
- : 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](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new#proxy) `proxy` setting for this user context.
- `unhandledPromptBehavior` {{optional_inline}}
- : 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](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new#unhandledpromptbehavior) `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 uniquely identifies the created user context.

### Errors

- `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](/en-US/docs/Web/WebDriver/How_to/Create_BiDi_connection) and an [active session](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new), send the following message to create a user context:

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

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

```json
{
"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:

```json
{
"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:

```json
{
"id": 2,
"type": "success",
"result": {
"userContext": "7d9e2a1b-5c3f-4e6d-8a7b-2c1d0e9f8a7b"
}
}
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new) command
- [`browser.getUserContexts`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/getUserContexts) command
- [`browser.removeUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/removeUserContext) command
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
title: browser.getClientWindows command
short-title: browser.getClientWindows
slug: Web/WebDriver/Reference/BiDi/Modules/browser/getClientWindows
page-type: webdriver-command
browser-compat: webdriver.bidi.browser.getClientWindows
sidebar: webdriver
---

The `browser.getClientWindows` [command](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules#commands) of the [`browser`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser) module returns a list of [client windows](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser#client_windows).

## Syntax

```json-nolint
{
"method": "browser.getClientWindows",
"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 client windows in the browser:

- `clientWindows`
- : An array of objects, each representing a client window.
The array may be empty if the browser has no open windows.
Each object has the following fields:
- `active`
- : A boolean that indicates whether the client window can receive keyboard input from the operating system.
This can mean a tab within the window has system focus, or the browser UI itself is focused.
- `clientWindow`
- : A string that uniquely identifies the client window.
- `height`
- : A number that indicates the height of the window in CSS pixels.
- `state`
- : A string that indicates the current state of the window.
- `"fullscreen"`
- : Indicates that the window is in fullscreen mode.
- `"maximized"`
- : Indicates that the window is maximized to fill the screen area.
- `"minimized"`
- : Indicates that the window is minimized (hidden from view).
- `"normal"`
- : Indicates that the window is in its normal (restored) state.
- `width`
- : A number that indicates the width of the window in CSS pixels.
- `x`
- : A number that indicates the x-coordinate of the window in CSS pixels, measured from the left edge of the screen area.
- `y`
- : A number that indicates the y-coordinate of the window in CSS pixels, measured from the top edge of the screen area.

## Examples

### Getting all client windows

With a [WebDriver BiDi connection](/en-US/docs/Web/WebDriver/How_to/Create_BiDi_connection) and an [active session](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new), send the following message to retrieve all client windows:

```json
{
"id": 1,
"method": "browser.getClientWindows",
"params": {}
}
```

The browser responds successfully with the list of client windows as follows:

```json
{
"id": 1,
"type": "success",
"result": {
"clientWindows": [
{
"active": true,
"clientWindow": "09a7bf22-c52d-4011-88ad-507a7e0012c7",
"height": 970,
"state": "normal",
"width": 1280,
"x": 4,
"y": 38
}
]
}
}
```

### Getting client windows when multiple browser windows are open

When multiple browser windows are open, the browser responds with one entry per window as follows:

```json
{
"id": 2,
"type": "success",
"result": {
"clientWindows": [
{
"active": true,
"clientWindow": "09a7bf22-c52d-4011-88ad-507a7e0012c7",
"height": 800,
"state": "normal",
"width": 1280,
"x": 0,
"y": 26
},
{
"active": false,
"clientWindow": "b3f8a1e5-d4c2-4e9f-8b3a-1f2e3d4c5b6a",
"height": 0,
"state": "minimized",
"width": 0,
"x": 0,
"y": 0
}
]
}
}
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new) command
- [`browser.setClientWindowState`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/setClientWindowState) command
Loading
Loading