WebDriver BiDi modules
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
- bluetooth module
The
bluetoothmodule contains commands for automating Bluetooth device interactions.- browser module
The
browsermodule contains commands for managing the browser.- browsingContext module
The
browsingContextmodule contains commands and events for managing browsing contexts.- emulation module
The
emulationmodule contains commands for overriding the behavior of certain Web APIs, such as the Geolocation API and the Screen Orientation API, to simulate different environments.- input module
The
inputmodule contains commands for simulating user input actions.- log module
The
logmodule contains events related to logging.- network module
The
networkmodule contains commands and events related to network requests.- permissions module
The
permissionsmodule contains commands for managing browser permissions.- script module
The
scriptmodule contains commands and events for executing JavaScript and managing script realms in the browser.- session module
The
sessionmodule contains commands for managing the lifecycle and event subscriptions of a WebDriver BiDi session.- storage module
The
storagemodule contains commands and events related to storage.- userAgentClientHints module
The
userAgentClientHintsmodule contains commands for overriding user agent client hints.- webExtension module
The
webExtensionmodule contains commands for managing browser extensions.
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. Theidlets you match each response to the command that triggered it.method: The command to run, in the formmodule_name.command_name.params: An object with any additional information the command needs. Some commands require no parameters, but an emptyparamsobject ({}) 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.
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",
"method": "log",
"realm": null,
"level": "info",
"text": "Hello world",
"timestamp": 1657282076037
}
}