Skip to content

Commit 1db2c61

Browse files
authored
[Editorial review] BiDi - Add pages for browsingContext module, part 1: context lifecycle commands (#44121)
* adds create command * adds close command * adds activate command * removes unfinished pages * fixes tech review feedback * fix review comments
1 parent b7de5fa commit 1db2c61

15 files changed

Lines changed: 419 additions & 12 deletions

File tree

files/en-us/web/webdriver/reference/bidi/modules/browser/createusercontext/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Set `params` to an empty object (`{}`) or include any of the following optional
3737
The following field in the `result` object of the response describes the created user context:
3838

3939
- `userContext`
40-
- : A string that contains the ID ([UUID](/en-US/docs/Glossary/UUID)) that uniquely identifies the created user context.
40+
- : A string that contains the ID that uniquely identifies the created user context.
4141

4242
### Errors
4343

files/en-us/web/webdriver/reference/bidi/modules/browser/getusercontexts/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The following field in the `result` object of the response describes the user co
3030
- : An array of one or more objects, each representing a user context.
3131
Each object has the following field:
3232
- `userContext`
33-
- : A string that contains the ID ([UUID](/en-US/docs/Glossary/UUID)) that uniquely identifies the user context.
33+
- : A string that contains the ID that uniquely identifies the user context.
3434
The default user context has the value `"default"`; it always exists and cannot be removed, so the array is never empty.
3535

3636
## Examples

files/en-us/web/webdriver/reference/bidi/modules/browser/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Each user context has a unique string identifier (user context ID). The browser
3131

3232
Multiple tabs from different user contexts can share the same [client window](#client_windows).
3333

34+
For example, a regular browser tab lives in the `"default"` user context.
35+
A tab opened in a separate container lives in a different user context.
36+
Both tabs can appear in the same client window, but their cookies and session data are completely isolated from each other.
37+
3438
User contexts can be created using [`browser.createUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/createUserContext) and removed using [`browser.removeUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/removeUserContext).
3539

3640
## Commands

files/en-us/web/webdriver/reference/bidi/modules/browser/removeusercontext/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The `browser.removeUserContext` [command](/en-US/docs/Web/WebDriver/Reference/Bi
2828
The `params` field contains:
2929

3030
- `userContext`
31-
- : A string that contains the ID ([UUID](/en-US/docs/Glossary/UUID)) of the user context to remove.
31+
- : A string that contains the ID of the user context to remove.
3232
User context IDs are returned by commands such as [`browser.createUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/createUserContext) or [`browser.getUserContexts`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/getUserContexts).
3333
The default user context (`"default"`) cannot be removed.
3434

files/en-us/web/webdriver/reference/bidi/modules/browser/setdownloadbehavior/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The `params` field contains:
3434
- : A string that specifies the path to the folder where downloaded files are saved.
3535
This field is required when `type` is `"allowed"`.
3636
- `userContexts` {{optional_inline}}
37-
- : An array of strings where each string is the ID ([UUID](/en-US/docs/Glossary/UUID)) of a [user context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser#user_contexts) to apply the download behavior to.
37+
- : An array of strings where each string is the ID of a [user context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser#user_contexts) to apply the download behavior to.
3838
User context IDs are returned by commands such as [`browser.createUserContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/createUserContext) or [`browser.getUserContexts`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browser/getUserContexts).
3939
- If included, the specified download behavior is applied to each listed user context. If `downloadBehavior` is `null`, the per-context override is reset for each listed user context.
4040
- If not included, the specified download behavior is applied as a global default to all user contexts.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: "`browsingContext.activate` command"
3+
short-title: activate
4+
slug: Web/WebDriver/Reference/BiDi/Modules/browsingContext/activate
5+
page-type: webdriver-command
6+
browser-compat: webdriver.bidi.browsingContext.activate
7+
sidebar: webdriver
8+
---
9+
10+
The `browsingContext.activate` [command](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules#commands) of the [`browsingContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext) module brings a [top-level context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext#top-level_context) to the foreground and gives it focus.
11+
12+
## Syntax
13+
14+
```json-nolint
15+
{
16+
"method": "browsingContext.activate",
17+
"params": {
18+
"context": "<contextId>"
19+
}
20+
}
21+
```
22+
23+
### Parameters
24+
25+
The `params` field contains:
26+
27+
- `context`
28+
- : A string that contains the ID of the [top-level context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext#top-level_context) to bring to the foreground and give focus.
29+
Context IDs are returned by commands such as [`browsingContext.getTree`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/getTree).
30+
31+
### Return value
32+
33+
The `result` field in the response is an empty object (`{}`).
34+
35+
### Errors
36+
37+
- [`invalid argument`](/en-US/docs/Web/WebDriver/Reference/Errors/InvalidArgument)
38+
- : A required parameter is missing or has an invalid type.
39+
This error is also returned when the context specified by `context` is not a top-level context.
40+
- `no such frame`
41+
- : No context with the given context ID is found.
42+
- `unsupported operation`
43+
- : The browser cannot bring the context to the foreground.
44+
45+
## Examples
46+
47+
### Activating a background tab
48+
49+
The following example shows how to activate a background tab.
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), suppose you create a tab in the background using [`browsingContext.create`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/create) with `background: true`, which returns the context ID of the tab. Send the following message to activate it:
52+
53+
```json
54+
{
55+
"id": 1,
56+
"method": "browsingContext.activate",
57+
"params": {
58+
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa"
59+
}
60+
}
61+
```
62+
63+
The browser brings the tab to the foreground and responds as follows:
64+
65+
```json
66+
{
67+
"id": 1,
68+
"type": "success",
69+
"result": {}
70+
}
71+
```
72+
73+
## Specifications
74+
75+
{{Specifications}}
76+
77+
## Browser compatibility
78+
79+
{{Compat}}
80+
81+
## See also
82+
83+
- [`browsingContext.close`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/close) command
84+
- [`browsingContext.create`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/create) command
85+
- [`browsingContext.getTree`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/getTree) command
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "`browsingContext.close` command"
3+
short-title: close
4+
slug: Web/WebDriver/Reference/BiDi/Modules/browsingContext/close
5+
page-type: webdriver-command
6+
browser-compat: webdriver.bidi.browsingContext.close
7+
sidebar: webdriver
8+
---
9+
10+
The `browsingContext.close` [command](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules#commands) of the [`browsingContext`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext) module closes the specified [top-level context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext#top-level_context).
11+
12+
## Syntax
13+
14+
```json-nolint
15+
{
16+
"method": "browsingContext.close",
17+
"params": {
18+
"context": "<contextId>"
19+
}
20+
}
21+
```
22+
23+
### Parameters
24+
25+
The `params` field contains:
26+
27+
- `context`
28+
- : A string that contains the ID of the [top-level context](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext#top-level_context) to close.
29+
Context IDs are returned by commands such as [`browsingContext.getTree`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/getTree).
30+
- `promptUnload` {{optional_inline}}
31+
- : A boolean that indicates whether the browser runs [`beforeunload`](/en-US/docs/Web/API/Window/beforeunload_event) event handlers before closing the context.
32+
The default value is `false`.
33+
- `false`: The specified context closes immediately without running `beforeunload` event handlers.
34+
- `true`: The browser runs `beforeunload` event handlers before closing the specified context.
35+
Any resulting prompt is handled as defined by the `unhandledPromptBehavior` capability specified via the [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new#unhandledpromptbehavior) command.
36+
37+
### Return value
38+
39+
The `result` field in the response is an empty object (`{}`).
40+
41+
### Errors
42+
43+
- [`invalid argument`](/en-US/docs/Web/WebDriver/Reference/Errors/InvalidArgument)
44+
- : A required parameter is missing or has an invalid type.
45+
This error is also returned when the context specified by `context` is not a top-level context.
46+
- `no such frame`
47+
- : No context with the given context ID is found.
48+
49+
## Examples
50+
51+
### Closing a tab with a page unload prompt
52+
53+
The following example shows how to close a tab and allow its [`beforeunload`](/en-US/docs/Web/API/Window/beforeunload_event) event handlers to run before closing.
54+
55+
With a [WebDriver BiDi connection](/en-US/docs/Web/WebDriver/How_to/Create_BiDi_connection), suppose a session is created via [`session.new`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/session/new) with `unhandledPromptBehavior` set to `"accept"`.
56+
First get the context ID using [`browsingContext.getTree`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/getTree), then send the following message:
57+
58+
```json
59+
{
60+
"id": 1,
61+
"method": "browsingContext.close",
62+
"params": {
63+
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
64+
"promptUnload": true
65+
}
66+
}
67+
```
68+
69+
The browser closes the context and responds as follows:
70+
71+
```json
72+
{
73+
"id": 1,
74+
"type": "success",
75+
"result": {}
76+
}
77+
```
78+
79+
Since `promptUnload` is `true`, the browser runs any `beforeunload` handlers on the page before closing.
80+
The confirmation prompt, if shown, is automatically accepted based on the `unhandledPromptBehavior` setting defined in `session.new`.
81+
82+
## Specifications
83+
84+
{{Specifications}}
85+
86+
## Browser compatibility
87+
88+
{{Compat}}
89+
90+
## See also
91+
92+
- [`browsingContext.activate`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/activate) command
93+
- [`browsingContext.create`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/create) command
94+
- [`browsingContext.getTree`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/getTree) command
95+
- [`browsingContext.contextDestroyed`](/en-US/docs/Web/WebDriver/Reference/BiDi/Modules/browsingContext/contextDestroyed) event

0 commit comments

Comments
 (0)