* refactor(core)!: require an engine on every target and a platform on every engine (ENG-1604) A target's platform now comes only from its engine. The target-level platform key, targets without an engine, engines without a platform, and e2e init --engine none are removed, as a maintainer exception to the deprecation window. API-only projects use a defineEngine stub target. * fix: address review on the target engine contract - Bump ATTACH_PROTOCOL to 4: the opening reply now requires `engine`, so an e2e mcp and e2e run of different versions fail at the handshake with the version mismatch error instead of on an invalid reply. - serveEngine checks the platform through describeEngine before it registers the engine, so a handle without one fails initialize with INVALID_CONFIG naming the engine, not an internal error. - The platform-without-engine message prints the platform with describeValue, which cannot throw on a BigInt or cyclic value. - Move the API-only example config to docs/examples/api-testing/without-browser/ so it is not the config of the web-backed orders example. - Show EngineHandle extending Omit<Engine, 'platform'> in engine.mdx. - Tests: keep fixture targets and engines on one platform (units, scheduler, screenshot-codec), assert the doctor fixture's status error, pin defineConfig refusing platform on one branch of a condition, and rename the Electron-only init test. * docs: trim the target and engine platform docs to the API they describe (ENG-1604) Drop the reasons, compatibility notes, and error message wording added earlier in this PR, revert unrelated rewording, and list platform among the required Engine members. * docs(api-testing): remove the section on running API tests without a browser (ENG-1604) The section showed a target with no engine, which targets no longer allow, and its replacement stub engine is not something to document. The translations' sections told readers to omit the engine. * chore(changeset): drop the link to the removed API testing section (ENG-1604) * refactor(core): require platform on EngineHandle and drop the older-copy checks (ENG-1604) EngineHandle.platform is required like Engine.platform. A handle from an older installed copy of @e2e-dev/core no longer gets its own type allowance or runtime check in describeEngine, serveEngine, target resolution, or e2e init's CI planning. connectEngine still rejects one, since it builds its handle with defineEngine. * fix: address review on the rebased target engine contract (ENG-1604) Main's full-page screenshot code in session.ts now reads the required engine directly, and its protocol tests declare a platform. The ja, zh, pt, and hi reference pages drop the target platform and --engine none, and the changeset says e2e mcp and e2e run must be the same release to attach. * test: give main's telemetry config tests an engine (ENG-1604) * docs(api-testing): restore the section on running API tests without a browser (ENG-1604) The section shows a target on an engine named empty, which drives nothing. The error for a target with a platform and no engine suggests the same engine, and the changeset points API-only projects here. * docs(api-testing): name the target api and give the empty engine platform none (ENG-1604)
@e2e-dev/web
The browser engine for e2e, built on
Playwright.
e2e ships no engine of its own: every target names the engine that drives
it, and this package is the one for browsers. It implements the public
@e2e-dev/core/engine contract (e2e/engine to the runner), so a device or
desktop engine plugs into the same seam with no privilege either way.
Install
npm install --save-dev e2e @e2e-dev/web
To drive a browser from a program without the test runner, install
@e2e-dev/core instead of e2e, and
import web from @e2e-dev/web/engine:
npm install @e2e-dev/core @e2e-dev/web
This package depends on playwright-core pinned to an exact version, so the
engine always runs the Playwright it was tested against. An app that depends
on Playwright itself keeps its own copy; the two share a browser cache only
when their versions match.
import type { E2EConfig } from 'e2e';
import { web } from '@e2e-dev/web';
export default {
targets: [{ name: 'web', engine: web(), app: { url: 'http://localhost:3000' } }],
} satisfies E2EConfig;
The target declares the app; the engine only drives it. The target's app
takes url (the base URL app.open() opens; required on a web() target),
command (a process the runner starts before the run and stops after it,
with readyUrl to poll, default url), environment (test, staging,
production; inferred from the host), and identity (a stable cache and
session key when the origin is ephemeral). web({ url }) and the other old
app options are INVALID_CONFIG. Browser options:
browser (chromium, firefox, webkit; default chromium; or a
BrowserProvider that leases hosted browsers, see below), viewport
({ width, height }; default 1280x720), testIdAttribute (the attribute
getByTestId and a node's testId read; default data-testid), userAgent
(the User-Agent every attempt sends and navigator.userAgent reports),
locale and timezoneId (the language and time zone every attempt runs in,
such as de-DE and Europe/Berlin), colorScheme and reducedMotion (the
prefers-color-scheme and prefers-reduced-motion every page reports, from
first paint; browser.emulateMedia changes them in a test), initScripts (scripts every document
runs before the page's own), webmcp (true launches Chromium or Firefox with
WebMCP on, for browser.webmcp), and
connect — attach to a remote browser over CDP instead of launching a local
one.
Attaching to a remote browser (connect)
Set connect.cdpEndpoint to attach over the Chrome DevTools Protocol rather
than launch. The resolver is async and called at worker init, and again at the
start of any attempt that finds the session dropped, so a hosted browser whose
endpoint is provisioned per run — a cloud session URL that is not known at
config load — resolves each time it is needed. The resolver receives an
AbortSignal that fires when the init or attempt is cancelled or exceeds its
budget; a browser that connects after that is detached, never used. CDP attach
is chromium-only, and disposing the engine detaches the session without
killing the remote process the host owns.
engine: web({
connect: { cdpEndpoint: async () => acquireCloudBrowserSession() },
});
For transport recovery, add connect.reconnectEndpoint(signal). This opts
into the remote browser's persistent default context. cdpEndpoint then
provisions a fresh, dedicated browser for every attempt, including retries;
reconnectEndpoint must return that same browser after a disconnect. The
engine verifies the default context ID and active page target ID, clears stale
references, and never repeats a dispatched operation. A missing target fails
the attempt. The host owns deleting the remote browser after cleanup.
This mode does not support headers, basicAuth, userAgent, locale, timezoneId, deviceScaleFactor, context reset, or session
state capture and restore. Recording resumes after reconnect, but a segment
lost during the disconnect remains unavailable. See the
Playwright reference
for the lifecycle and ownership contract.
Leasing hosted browsers (browser)
connect has no lifecycle: nothing tells the host when to delete the browser
it provisioned. Pass a BrowserProvider as browser instead and the engine
asks for a browser when one is needed and gives it back when its scope ends,
on every exit path. scope: 'worker' (the default) leases one browser per
worker slot in prepare and releases them in finish; a worker whose browser
drops leases a replacement itself. scope: 'attempt' leases a fresh browser in
every startAttempt and releases it in endAttempt, reattaching through the
lease's reconnectEndpoint after a transport drop, with the limits of
connect.reconnectEndpoint. A provider implies chromium and excludes
connect; no vendor ships in the package. See
Hosted browsers for the contract
and an example against a generic session API.
engine: web({
browser: {
name: 'hosted-browsers',
acquire: async (request) => ({ id: session.id, cdpEndpoint: session.cdpUrl }),
release: async (lease) => stopSession(lease.id),
},
});
The browser fixture
The engine contributes browser: navigation, routes, cookies, dialogs, frames,
downloads, keyboard and mouse, the page clock (browser.clock), plus expect(browser).toHaveURL() and
toHaveTitle() and toHaveClass(). Import test from this package to have it
typed; it is the same runtime test as e2e's.
import { test } from '@e2e-dev/web';
import { expect } from 'e2e';
test('signs in', async ({ app, screen, browser }) => {
await app.open('/login');
await screen.getByLabel('Email').fill('user@example.test');
await expect(browser).toHaveURL('/dashboard');
});
Browsers
A missing browser is downloaded once per run, in the runner process, after the tests are collected and before the app starts: the progress prints in the run log, the run's clock starts only once the download is done, and no launch or test timeout ever includes it. Workers launch the browser the runner installed.
In CI, install browsers as their own step instead, so the cost is visible and cacheable:
npx @e2e-dev/web install chromium --with-deps
It downloads the browsers for the Playwright version this package pins, the
ones the engine launches. Under pnpm, run the bin by name:
pnpm exec e2e-web install chromium --with-deps.
--with-deps also installs the system libraries a slim container image lacks.
Documentation
Full documentation lives at e2e.com/docs.