Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
browser automation

How to Use Web APIs for Browser Automation: CDP, WebDriver BiDi, Selenium, Playwright and Puppeteer

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To automate a browser with an API, your script launches or attaches to a browser, opens a page, performs actions, and observes results through an automation library or protocol. In practice, “web APIs” here means browser-control interfaces—not only JavaScript APIs that a website calls. The main choices are Chrome DevTools Protocol (CDP), the standards-based WebDriver BiDi protocol, and libraries such as Selenium, Playwright and Puppeteer.

This guide shows a reproducible Chrome workflow, explains when each protocol fits, and covers CI, versioning, events, failures and permissions.

What browser automation APIs actually do

An automation stack has three layers:

  • Browser: Chrome, Firefox, WebKit or another engine renders the site.
  • Protocol: CDP or WebDriver (including WebDriver BiDi) carries commands and events between your code and the browser.
  • Library or framework: Puppeteer, Selenium or Playwright supplies locators, waits, assertions, fixtures and higher-level workflows.

A typical run starts a browser, creates a tab, navigates with a URL, finds controls, clicks or types, waits for a state change, reads text or network events, asserts an outcome, and closes the session. Use automation only on sites and accounts where you have permission, and follow applicable site rules.

Choose a browser and pin the environment

Chrome for Testing

Chrome for Testing is a Chrome distribution intended for testing and automation. Its versioned downloads let a team pin the browser in local development and CI. Matching ChromeDriver binaries are released for WebDriver-based tools. Pinning avoids a passing test becoming a failure after an unplanned browser update.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Headful during development, headless in CI

Run a visible browser while writing selectors and diagnosing failures. For servers and CI, use headless mode. Chrome’s modern headless implementation shares the same browser implementation as headful Chrome, so the rendering engine is not a separate legacy product.

CDP versus WebDriver BiDi

Chrome DevTools Protocol (CDP)

CDP exposes commands and events for instrumenting Chromium, Chrome and other Blink-based browsers. It is useful for Chromium-specific capabilities such as low-level network, performance and debugging control. The protocol’s tip-of-tree definitions change frequently and have no guaranteed backward compatibility. Prefer a library’s supported API and pin compatible browser and library versions rather than coding directly against an unpinned protocol schema.

WebDriver BiDi

WebDriver BiDi is the W3C bidirectional protocol. A WebSocket connection allows automation code to receive events such as network requests, console messages and JavaScript errors while still issuing commands. Selenium’s documentation describes CDP support as temporary while browser vendors develop complete BiDi implementations.

Classic WebDriver is largely request/response oriented: send a command and wait for its result. BiDi adds an event stream, which is a better fit for logging, network observation and reactive diagnostics.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which protocol should you use?

Need Best starting point Reason and caveat
Chromium-only debugging or instrumentation CDP through a supported library Broad low-level Chromium control; protocol definitions can change without backward-compatibility guarantees.
Cross-browser, standards-oriented events WebDriver BiDi Two-way WebSocket events for network, logs and script errors; implementation coverage varies by browser and feature.
Many languages or distributed execution Selenium Broad language bindings and Selenium Grid orchestration; enable BiDi when event APIs are required.
One integrated test stack for Chromium, Firefox and WebKit Playwright Its own protocol and test features are high-level; CDP attachment is Chromium-only and lower fidelity.
JavaScript automation with Chrome and Firefox Puppeteer Chrome uses CDP by default, Firefox uses BiDi by default; production-ready BiDi support is available for both.

The decision is not just about an easy API. Check browser engines, programming language, event requirements, framework features, grid needs, version alignment and whether runs are visible or headless.

How do I automate a browser with an API?

Minimal Puppeteer workflow

Puppeteer is a JavaScript library maintained by Chrome’s Browser Automation team. It supports Chrome and Firefox. A documented typical workflow downloads a compatible Chrome for Testing binary and launches headless by default.

  1. Create a project and install Puppeteer: npm install puppeteer.
  2. Create automation.mjs with the following illustrative script.
  3. Run node automation.mjs; the script writes an assertion failure if the expected heading is missing.
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({headless: true});
try {
  const page = await browser.newPage();
  await page.goto('https://example.com', {waitUntil: 'networkidle2', timeout: 30000});
  await page.locator('h1').wait();
  const heading = await page.locator('h1').innerText();
  if (heading !== 'Example Domain') {
    throw new Error(`Unexpected heading: ${heading}`);
  }
  console.log('Browser check passed');
} finally {
  await browser.close();
}

Use stable roles, labels or test identifiers instead of brittle absolute XPath expressions. Wait for a meaningful state—an element, URL, response or application-ready marker—rather than adding arbitrary sleeps.

Playwright’s equivalent shape

Playwright’s documented model launches a browser, creates a page, navigates, performs actions and closes. It can launch Chromium, Firefox and WebKit.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { chromium } from 'playwright';

const browser = await chromium.launch({headless: true});
try {
  const page = await browser.newPage();
  await page.goto('https://example.com', {waitUntil: 'domcontentloaded'});
  await page.getByRole('heading', {name: 'Example Domain'}).waitFor();
  console.log(await page.title());
} finally {
  await browser.close();
}

Playwright’s connectOverCDP path supports Chromium-based browsers only and is significantly lower fidelity than a normal Playwright protocol connection. Launching an external browser with different arguments can also break Playwright features.

Selenium with WebDriver BiDi

Selenium connects frameworks to browsers through WebDriver and matching drivers such as ChromeDriver. To request BiDi in Selenium, enable the webSocketUrl capability in browser options. Exact method names differ by Selenium language binding; use the binding’s current BiDi logging, network and script APIs after the session starts.

# Python illustration
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.set_capability("webSocketUrl", True)
driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    assert driver.title == "Example Domain"
finally:
    driver.quit()

Classic WebDriver commands remain useful for navigation and element interaction. Add BiDi subscriptions when you need asynchronous console, network or JavaScript-error events instead of polling after every action.

Events, waits and reliable assertions

Prefer state-based waits

  • Wait for a locator to be visible, enabled or attached.
  • Wait for a URL change after navigation.
  • Wait for a specific network response when an action triggers an API call.
  • Use network-idle waits cautiously: analytics, advertisements or long polling may prevent true idleness.

Capture evidence on failure

On failure, save a screenshot, page HTML, console messages and the current URL. In BiDi-capable stacks, subscribe to console and JavaScript-error events. Keep artifacts tied to the pinned browser and test revision so a later diagnosis can reproduce the same conditions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Running browser automation in CI

  1. Install a pinned Chrome for Testing version (or let your framework install its documented compatible binary).
  2. Use headless mode and a fixed viewport, timezone and locale where those values affect rendering.
  3. Set explicit navigation and action timeouts; do not let a hung page consume the entire job.
  4. Run each test with an isolated profile or context so cookies and local storage cannot leak between tests.
  5. Publish screenshots, console logs and traces only on failure unless every run needs them.
  6. Retry only known transient failures. A retry should not hide a deterministic selector or assertion bug.

Container images must include the browser’s runtime dependencies and fonts. Resource-starved runners can cause timeouts that never occur locally; record CPU, memory and browser versions with the job.

Version compatibility and maintenance

Keep the trio aligned

Browser, driver and automation library versions form a compatibility set. Chrome for Testing provides versioned browser downloads and matching ChromeDriver releases. Puppeteer ties each release to a specific browser release to protect compatibility with its underlying protocols. Upgrade deliberately: change one component, run the full suite, then update the pinned image or lockfile.

Do not build a fragile CDP dependency

CDP’s tip-of-tree schema is not a stable cross-version contract. If a library exposes a supported wrapper for network interception, tracing or browser control, use that wrapper. If direct CDP is unavoidable, pin the browser and document the protocol version and commands used.

Common failures and fixes

Browser or driver will not start

  • Cause: missing Linux libraries, incompatible driver, or an executable blocked by the container.
  • Fix: use the framework’s supported browser install, a matching Chrome for Testing/ChromeDriver pair, and a CI image with required dependencies. Print versions before the test.

Element not found or click intercepted

  • Cause: a race, iframe, shadow DOM, responsive layout or overlay.
  • Fix: wait for the element’s state, target its accessible role or test ID, switch to the correct frame, and capture a failure screenshot. Do not “fix” every failure with a long sleep.

Navigation times out

  • Cause: slow server, never-ending requests, blocked DNS, or an overly strict idle condition.
  • Fix: verify the URL from the runner, set a realistic timeout, wait for DOM content when appropriate, and inspect network events. A timeout is not proof that the page is unavailable to every client.

CDP attachment behaves differently from normal Playwright

Cause: Playwright documents CDP connection as Chromium-only and lower fidelity than its own protocol. Fix: launch with Playwright when possible; attach over CDP only when an existing Chromium session is a requirement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Automation is detected

Browser sites can distinguish trusted events using the isTrusted flag or related event patterns. Puppeteer’s generated input events are trusted, but that does not defeat bot detection or grant permission to access a site. Treat detection as a site-policy and authorization issue, not a selector problem.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a clean image or PDF rather than interactive testing, ScreenshotNeo provides a website screenshot API and MCP server. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing status.

One GET request returns PNG, JPEG, WebP or PDF. See the ScreenshotNeo API documentation for all options, including full-page lazy-image loading, CSS-selector elements, dark mode, device presets, retina scale, PDF margins and ranges, custom CSS/JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous webhooks, 100-URL bulk capture and usage data.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

There is also an MCP server with take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cost, performance and reliability choices

  • Local browser runs: no per-shot API fee, but you own browser downloads, compute, dependency updates and failure diagnosis.
  • Grid or remote browsers: useful for parallel cross-browser coverage, with added infrastructure and network variability.
  • Screenshot API: simpler for rendered artifacts and scheduled captures; check billing semantics, caching and failure reporting before scaling.
  • Parallelism: cap concurrent contexts to the runner’s CPU and memory. More workers can increase queueing and flakiness rather than reduce duration.

Measure navigation time, action time, browser startup and artifact upload separately. Reuse a browser process when isolation allows it, but create a fresh context per test group to prevent state leakage.

Should I use Selenium, Playwright, or Puppeteer?

Choose Selenium when your organization needs many language bindings, existing WebDriver infrastructure or Selenium Grid. Choose Playwright when one API should cover Chromium, Firefox and WebKit with integrated waiting and test tooling. Choose Puppeteer for JavaScript-focused Chrome/Firefox automation and direct access to its supported protocol abstractions. Choose WebDriver BiDi when standards-oriented, bidirectional events matter across supported browsers. Choose CDP when Chromium-specific instrumentation is worth accepting a fast-changing protocol contract.

Frequently Asked Questions

How do I automate a browser with an API?

Install a browser-automation library, launch or attach to a browser, create a page, navigate, interact through stable locators, wait for a meaningful state, assert the result, collect diagnostics and close the session.

What is the difference between CDP and WebDriver BiDi?

CDP is a Chromium-oriented instrumentation protocol with rapidly changing tip-of-tree definitions. WebDriver BiDi is a W3C bidirectional WebSocket protocol designed to deliver browser events such as network and console messages alongside commands.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can Puppeteer automate Firefox?

Yes. Puppeteer supports Firefox; its FAQ says Chrome uses CDP by default and Firefox uses BiDi by default, with production-ready BiDi support for both browsers.

How do I run browser automation in CI?

Pin the browser and driver, install runtime dependencies, run headless with explicit timeouts and isolated contexts, and publish screenshots and logs for failures.

Are automated events allowed on every website?

No universal permission follows from a protocol or library. Automate only where you are authorized and comply with the site’s terms and applicable rules.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.