WebDriver BiDi: 2023 status update

WebDriver BiDi: 2023 status update

This article gives an overview of what’s new in WebDriver BiDi in 2023.

What is WebDriver BiDi?

WebDriver is a browser automation protocol, defined as a W3C standard, with implementations in ChromeDriver, GeckoDriver, and WebKitDriver.

Chromium also has its own proprietary browser automation protocol: the Chrome DevTools Protocol, or CDP.

There are some fundamental differences between these two protocols: WebDriver is an interoperable standard, but the protocol is less efficient and lacks features that CDP has. In contrast, CDP is more efficient and powerful, but less interoperable.

That’s why in 2020, the W3C Browser Testing and Tools Working Group began work on WebDriver BiDi, a new standard browser automation protocol that bridges the gap between the WebDriver Classic and CDP protocols. The best of both worlds! Read A look back in time: the evolution of test automation and WebDriver BiDi — the future of cross-browser automation for more background.

The WebDriver BiDi effort involves standardization work, the creation of Web Platform Tests, and implementations for different browser engines.

Where are we now?

In 2022, both Chrome/ChromeDriver 106 and Firefox 102 shipped support for the WebDriver BiDi standard.

Since then, WebDriver BiDi gained adoption in popular frameworks, addressing top developer pain points by unlocking highly requested features such as logging support.

Logging powered by WebDriver BiDi

A common use case is to automatically verify that a web page loads without any console logs, warnings, or errors and without any uncaught JavaScript exceptions. Another use case is that you may wish to write an automated test to check that a web page logs a warning or throws an exception when intended. These problems can’t be solved using WebDriver Classic because it’s not bidirectional. WebDriver BiDi now makes this possible.

Here’s an example implementation of the second use case using Selenium’s JavaScript language bindings:

import * as assert from 'node:assert';
import { Builder, LogInspector } from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome.js';

const driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options().enableBidi())
.build();

const inspector = await LogInspector(driver);
await inspector.onConsoleEntry((entry) => {
console.log(`Console message received: ${entry.text}`);
});

await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html');
await driver.findElement({ id: 'consoleLog' }).click();

await driver.quit();

Here’s an example using Puppeteer’s experimental WebDriver BiDi support:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({
protocol: 'webDriverBiDi',
headless: 'new',
});

const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();

page.on('console', (message) => {
console.log(`Console message received: ${message.text()}`);
});

await page.goto(`https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html`);
await page.evaluate(() => {
document.querySelector('#consoleLog').click();
});

await browser.close();

The same functionality is available via other abstractions such as WebdriverIO.

A shared public roadmap

We’re still fleshing out the WebDriver BiDi specification in collaboration with other browser vendors and industry stakeholders who participate in the W3C Working Group. The group recently agreed on a shared roadmap, aligning the upcoming specification and implementation work around clear user-facing end-to-end use cases.

Interoperability

As the Working Group collectively specifies more features, we also create Web Platform Tests for the WebDriver BiDi protocol. This shared test suite helps us verify correctness and interoperability of implementations. You can view the latest test results for various browsers on the WPT Dashboard.

Supporting WebDriver BiDi: How can you help?

Are you excited about the future of browser automation with WebDriver BiDi? Here’s how you can show your support:

  • Be an early tester and adopter and help shape the future of WebDriver BiDi.
  • Spread the word! Share the project on social media using the hashtag #WebDriverBiDi.
  • Ask for support. File a feature request or check with your favorite tools on their plans for adopting WebDriver BiDi.
  • Participate in the spec discussions.

This post is also available in: English