> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# WebDriver BiDi

> Run browser tests on Chromium or Firefox over the W3C WebDriver BiDi protocol with the experimental @e2e-dev/bidi engine.

`@e2e-dev/bidi` is a browser engine that drives Chromium or Firefox over
[WebDriver BiDi](https://w3c.github.io/webdriver-bidi/), the W3C protocol
both browsers speak. Tests use the same `agent`, `screen`, and `expect` APIs
as on the [web engine](https://e2e.com/docs/web), and a `browser` fixture with the same names.

<Warning>
  **The BiDi engine is experimental.** It covers fewer `browser` features
  than `@e2e-dev/web`, and its options and behavior can change in any
  release, including a patch. Pin `@e2e-dev/bidi` to an exact version and read
  the [release notes](https://github.com/e2e-inc/e2e/releases) before you
  upgrade. For production suites, use [`@e2e-dev/web`](https://e2e.com/docs/web).
</Warning>

## Set up

Install the runner and the engine:

<CodeGroup>
```bash npm
npm install --save-dev e2e @e2e-dev/bidi
```

```bash pnpm
pnpm add --save-dev e2e @e2e-dev/bidi
```

```bash bun
bun add --dev e2e @e2e-dev/bidi
```
</CodeGroup>

The engine downloads its pinned browser build (Chrome for Testing 158 or
Firefox 161) the first time a run needs it, checks the download's SHA-256,
and caches it per user, or in `E2E_BIDI_BROWSERS_PATH` when you set it. Run
`npx e2e doctor` to see whether it's installed.

Unless you set `executablePath`, a headless Chromium run uses Chrome for
Testing's `chrome-headless-shell`, as `@e2e-dev/web` does, and `--headed`
uses full Chrome. An `executablePath` is launched as given. Full Chrome runs
its macOS window code even when headless, and on macOS that sometimes
crashes it a few seconds after launch. If `executablePath` points at full
Chrome, a headless run there can lose the browser the same way.

Firefox on Windows is the exception: Mozilla ships it there as an installer
only, so the engine can't download it, and `e2e doctor` reports a failure.
Install Firefox and set `executablePath` to its `firefox.exe`, or use
Chromium.

## Point at your app

A `bidi()` target opens its app at `app.url`, like a web target:

```ts title="e2e.config.ts"

export default {
  targets: [
    { name: 'chromium', engine: bidi(), app: { url: 'http://localhost:3000' } },
    { name: 'firefox', engine: bidi({ browser: 'firefox' }), app: { url: 'http://localhost:3000' } },
  ],
} satisfies E2EConfig;
```

Chromium speaks BiDi through the
[chromium-bidi](https://github.com/GoogleChromeLabs/chromium-bidi) mapper,
which the engine runs in a child process. Firefox speaks it natively. Neither
needs chromedriver, geckodriver, or Playwright.

| Option | Type | Default |
| --- | --- | --- |
| `browser` | `'chromium' \| 'firefox'` | `'chromium'` |
| `executablePath` | `string`, absolute or from the project root | the pinned build |
| `args` | `string[]`, extra browser arguments | `[]` |
| `viewport` | `{ width, height }` in CSS pixels | `1280` by `720` |
| `testIdAttribute` | the attribute `getByTestId` reads | `'data-testid'` |
| `settle` | ms to wait after an agent action, or `false` | `100` |

`args` can't set the profile, the debugging endpoint, or headless mode: the
engine owns those. Run with `--headed` to see the browser.

## Write a test

Import `test` from `@e2e-dev/bidi`. Each attempt gets its own user context,
so it starts with no cookies, storage, or tabs from another test.

```ts title="tests/sign-in.e2e.ts"

test('signs in', async ({ app, browser, screen }) => {
  await app.open('/sign-in');
  await screen.getByLabel('Email').fill('ada@example.test');
  await screen.getByRole('button', 'Sign in').tap();
  await expect(browser).toHaveURL(/\/dashboard$/);
  expect(await browser.cookies()).toContainEqual(expect.objectContaining({ name: 'session' }));
});
```

A test written for `@e2e-dev/web` runs here unchanged when it uses only the
members below.

## What the browser fixture covers

| Area | Members |
| --- | --- |
| Navigation | `goto`, `reload`, `back`, `forward`, `url`, `title`, `waitForURL` |
| Page | `locator`, `frameLocator`, `evaluate` |
| Input | `keyboard.press`, `down`, `up`, `type`; `mouse.move`, `wheel`, `down`, `up` |
| Cookies | `cookies`, `setCookies`, `clearCookies` |
| Tabs and dialogs | `tabs`, `newTab`, `waitForPopup`, `onDialog` |
| Viewport | `setViewport` |
| Matchers | `expect(browser).toHaveURL`, `toHaveTitle`, `toHaveClass` |

Sessions work too: a setup test's `session.save()` keeps the user context's
cookies and each open origin's `localStorage`, and a restore replaces them.
See [Authentication](https://e2e.com/docs/authentication).

### Not supported yet

- `browser.route()` and other network interception, `browser.clock`, video,
  and downloads
- `app.permissions`, emulation (geolocation, locale, color scheme), and
  hosted browser providers
- An HTML drag starts in the page: the drag events it fires aren't trusted,
  so an app that checks `event.isTrusted` on them ignores the drop

### On Firefox

Firefox handles input the way it does for a person, so a test written on
Chromium can see a different result there:

- `<input type="month">` and `type="week"` are plain text fields.
- After a tap opens a `<select>`, the next tap closes its list and reaches
  nothing else.
- A key pressed while Alt is held still types its character.

## Next

<CardGroup cols={2}>
  <Card title="Web" icon="globe" href="/web">
    The stable browser engine, with the full `browser` fixture.
  </Card>
  <Card title="Engines" icon="gears" href="/engines">
    How engines plug into e2e, and how to write one.
  </Card>
</CardGroup>
