The browsingContext.handleUserPrompt command of the browsingContext module closes an open user prompt: an Window.alert, Window.confirm, Window.prompt, or Window.beforeunload_event prompt.
Syntax
/* With required parameters */
{
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f"
}
}
/* With required and optional parameters */
{
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
"accept": true,
"userText": "some input text"
}
}
Parameters
The params field contains:
accept-
: A boolean that indicates whether to accept or dismiss the prompt; its effect depends on the prompt type.
For an Window.alert, this value has no effect and the prompt is always acknowledged. For the other prompt types:
-
true: This is the default.For a Window.confirm, the action is confirmed. For a Window.prompt, the prompt is submitted with the value of
userText. For a Window.beforeunload_event prompt, the navigation is confirmed. -
false:For a
confirm(), the action is declined. For aprompt(), the prompt is canceled. For abeforeunloadprompt, the navigation is refused.
-
-
context- : A string that contains the ID of the context that has the user prompt to close.
Context IDs are returned by commands such as
browsingContext.getTree.
- : A string that contains the ID of the context that has the user prompt to close.
Context IDs are returned by commands such as
userText- : A string that specifies the value to submit for a
prompt(). This field is ignored for prompt types other thanprompt(). If not specified, it defaults to an empty string.
- : A string that specifies the value to submit for a
Return value
The result field in the response is an empty object ({}).
The browsingContext.userPromptClosed event fires when the prompt is closed.
Errors
-
- : A required parameter is missing or has an invalid type.
-
no such frame- : No context with the given context ID is found.
-
no such alert- : The context specified by
contextdoes not have a user prompt.
- : The context specified by
Examples
Accepting a confirm() prompt
With a WebDriver BiDi connection and an active session, suppose a page calls confirm(), opening a prompt that blocks the page.
Listen for the browsingContext.userPromptOpened event to detect the prompt, then send the following message to accept it:
{
"id": 1,
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"accept": true
}
}
The browser closes the prompt and responds as follows:
{
"id": 1,
"type": "success",
"result": {}
}
Accepting a prompt() with text
Using the same connection and session, suppose a page calls prompt() and shows the resulting text input dialog.
Send the following message to submit a value:
{
"id": 2,
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"accept": true,
"userText": "example input"
}
}
The browser responds as follows:
{
"id": 2,
"type": "success",
"result": {}
}
Specifications
Browser compatibility
See also
browsingContext.getTreecommandbrowsingContext.navigatecommandbrowsingContext.reloadcommandbrowsingContext.userPromptOpenedeventbrowsingContext.userPromptClosedevent
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
