大网数据广告活动
Web 标准与前端开发

`browsingContext.handleUserPrompt` command

· 52CE 我爱测

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.

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 a prompt(), the prompt is canceled. For a beforeunload prompt, 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.
  • userText
    • : A string that specifies the value to submit for a prompt(). This field is ignored for prompt types other than prompt(). If not specified, it defaults to an empty string.

Return value

The result field in the response is an empty object ({}). The browsingContext.userPromptClosed event fires when the prompt is closed.

Errors

  • invalid argument

    • : 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 context does not have a user prompt.

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

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。