Skip to content

Commit c09036b

Browse files
dipikabhpepelsbey
andauthored
[Editorial review] BiDi - Add pages for browser module commands (#43518)
* browser get, create usercontext commands * update landing page and sidebar * pages for browser removeusercontext, close commands * adds browser getclientwindows page * addresses review feedback * Apply suggestions from code review Co-authored-by: Vadim Makeev <hi@pepelsbey.dev> --------- Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
1 parent 349453f commit c09036b

File tree

9 files changed

+563
-5
lines changed

9 files changed

+563
-5
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: browser.close command
3+
short-title: browser.close
4+
slug: Web/WebDriver/Reference/BiDi/Modules/browser/close
5+
page-type: webdriver-command
6+
browser-compat: webdriver.bidi.browser.close
7+
sidebar: webdriver
8+
---
9+
10+
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.
11+
12+
## Syntax
13+
14+
```json-nolint
15+
{
16+
"method": "browser.close",
17+
"params": {}
18+
}
19+
```
20+
21+
### Parameters
22+
23+
None. However, you must include the `params` field and set it to an empty object (`{}`).
24+
25+
### Return value
26+
27+
The `result` field in the response is an empty object (`{}`).
28+
29+
### Errors
30+
31+
- `unable to close browser`
32+
- : There are other active WebDriver sessions open at the time the command is sent.
33+
Browsers may return this error before continuing to close.
34+
35+
## Examples
36+
37+
### Closing the browser
38+
39+
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:
40+
41+
```json
42+
{
43+
"id": 1,
44+
"method": "browser.close",
45+
"params": {}
46+
}
47+
```
48+
49+
Before closing, the browser responds successfully as shown here:
50+
51+
```json
52+
{
53+
"id": 1,
54+
"type": "success",
55+
"result": {}
56+
}
57+
```
58+
59+
After the response, the WebSocket connection closes as the browser shuts down.
60+
61+
## Specifications
62+
63+
{{Specifications}}
64+
65+
## Browser compatibility
66+
67+
{{Compat}}
68+
69+
## See also
70+
71+
- [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new) command
72+
- [`session.end`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/end) command
73+
- [`browser.createUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/createUserContext) command
74+
- [`browser.getUserContexts`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/getUserContexts) command
75+
- [`browser.removeUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/removeUserContext) command
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: browser.createUserContext command
3+
short-title: browser.createUserContext
4+
slug: Web/WebDriver/Reference/BiDi/Modules/browser/createUserContext
5+
page-type: webdriver-command
6+
browser-compat: webdriver.bidi.browser.createUserContext
7+
sidebar: webdriver
8+
---
9+
10+
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.
11+
12+
## Syntax
13+
14+
```json-nolint
15+
{
16+
"method": "browser.createUserContext",
17+
"params": {}
18+
}
19+
```
20+
21+
### Parameters
22+
23+
Set `params` to an empty object (`{}`) or include any of the following optional fields:
24+
25+
- [`acceptInsecureCerts`](/en-US/docs/Web/WebDriver/Reference/Capabilities/acceptInsecureCerts) {{optional_inline}}
26+
- : 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.
27+
- `proxy` {{optional_inline}}
28+
- : 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.
29+
- `unhandledPromptBehavior` {{optional_inline}}
30+
- : 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.
31+
32+
> [!NOTE]
33+
> When a parameter is set, it applies to all existing and future tabs within this user context.
34+
35+
### Return value
36+
37+
The following field in the `result` object of the response describes the created user context:
38+
39+
- `userContext`
40+
- : A string that uniquely identifies the created user context.
41+
42+
### Errors
43+
44+
- `unsupported operation`
45+
- : `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.
46+
47+
## Examples
48+
49+
### Creating a user context with default settings
50+
51+
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:
52+
53+
```json
54+
{
55+
"id": 1,
56+
"method": "browser.createUserContext",
57+
"params": {}
58+
}
59+
```
60+
61+
The browser responds with a successful user context creation as follows:
62+
63+
```json
64+
{
65+
"id": 1,
66+
"type": "success",
67+
"result": {
68+
"userContext": "4e4b1f6d-3f1a-4b2e-9f8c-1a2b3c4d5e6f"
69+
}
70+
}
71+
```
72+
73+
### Creating a user context with a proxy
74+
75+
Send the following message to create a user context that routes network requests through a proxy:
76+
77+
```json
78+
{
79+
"id": 2,
80+
"method": "browser.createUserContext",
81+
"params": {
82+
"proxy": {
83+
"proxyType": "manual",
84+
"httpProxy": "127.0.0.1:80"
85+
}
86+
}
87+
}
88+
```
89+
90+
The browser responds with a successful user context creation as follows:
91+
92+
```json
93+
{
94+
"id": 2,
95+
"type": "success",
96+
"result": {
97+
"userContext": "7d9e2a1b-5c3f-4e6d-8a7b-2c1d0e9f8a7b"
98+
}
99+
}
100+
```
101+
102+
## Specifications
103+
104+
{{Specifications}}
105+
106+
## Browser compatibility
107+
108+
{{Compat}}
109+
110+
## See also
111+
112+
- [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new) command
113+
- [`browser.getUserContexts`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/getUserContexts) command
114+
- [`browser.removeUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/removeUserContext) command
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
title: browser.getClientWindows command
3+
short-title: browser.getClientWindows
4+
slug: Web/WebDriver/Reference/BiDi/Modules/browser/getClientWindows
5+
page-type: webdriver-command
6+
browser-compat: webdriver.bidi.browser.getClientWindows
7+
sidebar: webdriver
8+
---
9+
10+
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).
11+
12+
## Syntax
13+
14+
```json-nolint
15+
{
16+
"method": "browser.getClientWindows",
17+
"params": {}
18+
}
19+
```
20+
21+
### Parameters
22+
23+
None. However, you must include the `params` field and set it to an empty object (`{}`).
24+
25+
### Return value
26+
27+
The following field in the `result` object of the response describes the client windows in the browser:
28+
29+
- `clientWindows`
30+
- : An array of objects, each representing a client window.
31+
The array may be empty if the browser has no open windows.
32+
Each object has the following fields:
33+
- `active`
34+
- : A boolean that indicates whether the client window can receive keyboard input from the operating system.
35+
This can mean a tab within the window has system focus, or the browser UI itself is focused.
36+
- `clientWindow`
37+
- : A string that uniquely identifies the client window.
38+
- `height`
39+
- : A number that indicates the height of the window in {{glossary("CSS pixel", "CSS pixels")}}.
40+
- `state`
41+
- : A string that indicates the current state of the window.
42+
- `"fullscreen"`
43+
- : Indicates that the window is in fullscreen mode.
44+
- `"maximized"`
45+
- : Indicates that the window is maximized to fill the screen area.
46+
- `"minimized"`
47+
- : Indicates that the window is minimized (hidden from view).
48+
- `"normal"`
49+
- : Indicates that the window is in its normal (restored) state.
50+
- `width`
51+
- : A number that indicates the width of the window in {{glossary("CSS pixel", "CSS pixels")}}.
52+
- `x`
53+
- : A number that indicates the x-coordinate of the window in {{glossary("CSS pixel", "CSS pixels")}}, measured from the left edge of the screen area.
54+
- `y`
55+
- : A number that indicates the y-coordinate of the window in {{glossary("CSS pixel", "CSS pixels")}}, measured from the top edge of the screen area.
56+
57+
## Examples
58+
59+
### Getting all client windows
60+
61+
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:
62+
63+
```json
64+
{
65+
"id": 1,
66+
"method": "browser.getClientWindows",
67+
"params": {}
68+
}
69+
```
70+
71+
The browser responds successfully with the list of client windows as follows:
72+
73+
```json
74+
{
75+
"id": 1,
76+
"type": "success",
77+
"result": {
78+
"clientWindows": [
79+
{
80+
"active": true,
81+
"clientWindow": "09a7bf22-c52d-4011-88ad-507a7e0012c7",
82+
"height": 970,
83+
"state": "normal",
84+
"width": 1280,
85+
"x": 4,
86+
"y": 38
87+
}
88+
]
89+
}
90+
}
91+
```
92+
93+
### Getting client windows when multiple browser windows are open
94+
95+
When multiple browser windows are open, the browser responds with one entry per window as follows:
96+
97+
```json
98+
{
99+
"id": 2,
100+
"type": "success",
101+
"result": {
102+
"clientWindows": [
103+
{
104+
"active": true,
105+
"clientWindow": "09a7bf22-c52d-4011-88ad-507a7e0012c7",
106+
"height": 800,
107+
"state": "normal",
108+
"width": 1280,
109+
"x": 0,
110+
"y": 26
111+
},
112+
{
113+
"active": false,
114+
"clientWindow": "b3f8a1e5-d4c2-4e9f-8b3a-1f2e3d4c5b6a",
115+
"height": 0,
116+
"state": "minimized",
117+
"width": 0,
118+
"x": 0,
119+
"y": 0
120+
}
121+
]
122+
}
123+
}
124+
```
125+
126+
## Specifications
127+
128+
{{Specifications}}
129+
130+
## Browser compatibility
131+
132+
{{Compat}}
133+
134+
## See also
135+
136+
- [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new) command
137+
- [`browser.setClientWindowState`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/setClientWindowState) command

0 commit comments

Comments
 (0)