browsingContext.close command
The browsingContext.close command of the browsingContext module closes the specified top-level context.
Syntax
{
"method": "browsingContext.close",
"params": {
"context": "<contextId>"
}
}
Parameters
The params field contains:
context-
A string that contains the ID of the top-level context to close. Context IDs are returned by commands such as
browsingContext.getTree. promptUnloadOptional-
A boolean that indicates whether the browser runs
beforeunloadevent handlers before closing the context. The default value isfalse.false: The specified context closes immediately without runningbeforeunloadevent handlers.true: The browser runsbeforeunloadevent handlers before closing the specified context. Any resulting prompt is handled as defined by theunhandledPromptBehaviorcapability specified via thesession.newcommand.
Return value
The result field in the response is an empty object ({}).
Errors
invalid argument-
A required parameter is missing or has an invalid type. This error is also returned when the context specified by
contextis not a top-level context. no such frame-
No context with the given context ID is found.
Examples
>Closing a tab with a page unload prompt
The following example shows how to close a tab and allow its beforeunload event handlers to run before closing.
With a WebDriver BiDi connection, suppose a session is created via session.new with unhandledPromptBehavior set to "accept".
First get the context ID using browsingContext.getTree, then send the following message:
{
"id": 1,
"method": "browsingContext.close",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"promptUnload": true
}
}
The browser closes the context and responds as follows:
{
"id": 1,
"type": "success",
"result": {}
}
Since promptUnload is true, the browser runs any beforeunload handlers on the page before closing.
The confirmation prompt, if shown, is automatically accepted based on the unhandledPromptBehavior setting defined in session.new.
Specifications
| Specification |
|---|
| WebDriver BiDi> # command-browsingContext-close> |
Browser compatibility
See also
browsingContext.activatecommandbrowsingContext.createcommandbrowsingContext.getTreecommandbrowsingContext.contextDestroyedevent