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

WebDriver BiDi modules

· 52CE 我爱测

The WebDriver BiDi protocol is organized into modules. Each module represents a collection of related commands and events used in specific browser automation cases.

The WebDriver BiDi protocol is organized into modules. Each module represents a collection of related commands and events used in specific browser automation cases.

Both command and event names use the module name as a prefix: module_name.command_name for commands and module_name.event_name for events.

List of modules

Commands

A command is an asynchronous operation sent from the client to the browser. Each command message you send to the browser has three fields:

  • id: A number you assign to the command. Unlike HTTP where each request waits for a response, a WebSocket connection can have multiple commands in flight at the same time and responses may arrive out of order. The id lets you match each response to the command that triggered it.
  • method: The command to run, in the form module_name.command_name.
  • params: An object with any additional information the command needs. Some commands require no parameters, but an empty params object ({}) must still be sent.

For example, to create a new session, you would send the session.new command as follows:

{
  "id": 1,
  "method": "session.new",
  "params": {}
}

Each command results in either a success response containing a result field or an error response containing an error field. The structure of result is specific to each command.

All commands except session.new and session.status require an active WebDriver BiDi session.

Events

An event is a notification sent by the browser to the client when something of interest occurs. To receive events, the client must first subscribe to them using the session.subscribe command.

The client can subscribe to a specific event or to all events in a module. For example, subscribing to "browsingContext.contextCreated" subscribes the client to that single event, while subscribing to "browsingContext" subscribes the client to every event in the browsingContext module.

Every event notification you receive from the browser has three fields:

  • type: Always "event".
  • method: The event name, in the form module_name.event_name.
  • params: An object containing the event-specific data. The structure of params is specific to each event.

The following is a sample event message sent by the browser when the client is subscribed to log.entryAdded and a console message is logged (some fields have been omitted for brevity):

{
  "type": "event",
  "method": "log.entryAdded",
  "params": {
    "type": "console",
    "level": "info",
    "text": "Hello world",
    "timestamp": 1657282076037,
    "method": "log"
  }
}

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

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

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