browsingContext.close commandThe browsingContext.close command of the browsingContext module closes the specified top-level context.
/* With required parameters */
{
"method": "browsingContext.close",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f"
}
}
/* With required and optional parameters */
{
"method": "browsingContext.close",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
"promptUnload": true
}
}The params field contains:
contextA string that contains the ID of the top-level context to close. Context IDs are returned by commands such as browsingContext.getTree.
promptUnload OptionalA boolean that indicates whether the browser runs beforeunload event handlers before closing the context.
false: The specified context closes immediately without running beforeunload event handlers. This is the default.true: The browser runs beforeunload event handlers before closing the specified context. Any resulting prompt is handled as defined by the unhandledPromptBehavior capability specified via the session.new command.The result field in the response is an empty object ({}).
invalid argumentA required parameter is missing or has an invalid type. This error is also returned when the context specified by context is not a top-level context.
no such frameNo context with the given context ID is found.
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.
browsingContext.activate commandbrowsingContext.create commandbrowsingContext.getTree commandbrowsingContext.contextDestroyed event