Skip to content

Errors

This page summarizes errors surfaced by routes, the Node agent, and the proxy.

Abort codes

route.abort(errorCode?) uses backend network error codes on the wire.

CodeDefault message
failednet::ERR_FAILED
abortednet::ERR_ABORTED
timedoutnet::ERR_TIMED_OUT
connectionrefusednet::ERR_CONNECTION_REFUSED
connectionresetnet::ERR_CONNECTION_RESET
namenotresolvednet::ERR_NAME_NOT_RESOLVED

Default when omitted: failed.

The public route type accepts Playwright abort strings, but unsupported strings collapse to failed before reaching the Node agent.

BackendMocksNetworkError

Package: @playwright-backend-mocks/protocol

ts
class BackendMocksNetworkError extends Error {
  readonly code: BackendErrorCode;
}

Helpers exported by the protocol package:

ts
function errorFromCode(
  code: BackendErrorCode,
  message?: string,
): BackendMocksNetworkError;

function serializeError(error: unknown): SerializedError;

Application tests usually do not import these helpers. They call route.abort() and assert on app behavior.

Proxy decision errors

CodeMeaning
ambiguous_routeMore than one test claimed the same HTTP request or WebSocket connection.
claim_timeoutAt least one expected Playwright test did not answer the claim in time.
disconnectedThe matched Playwright worker or Node agent disconnected.
handler_failedReserved for handler failure messages.
internalCoordination failed for an unexpected reason.

Proxy errors are stored in the current test's backendMocks error buffer. Remaining errors fail fixture teardown.

ts
const errors = backendMocks.takeErrors();
expect(errors[0]?.message).toMatch(/Ambiguous backend mock routing/);

Only drain errors that the test intentionally triggers.

Handler errors

If an HTTP route handler throws:

  1. The error is recorded on the test's error buffer.
  2. The paused Node request is aborted with failed.
  3. Fixture teardown throws if the error is not drained.

Fetch and waiter errors

APIError
route.fetch({ timeout })Rejects with Timeout ${timeout}ms exceeded.
route.fetch({ signal })Rejects with the abort reason or route.fetch aborted.
waitForRequest({ timeout })Rejects after timeout waiting for event "request".
waitForResponse({ timeout })Rejects after timeout waiting for event "response".
Waiter with AbortSignalRejects with the abort reason or The operation was aborted.

Pass timeout: 0 to disable route fetch and waiter timeouts.

Handshake errors

CauseResult
Protocol version mismatchhello:error with protocol_mismatch; socket closes.
Wrong or missing tokenhello:error with unauthorized; socket closes.
Package version mismatchProxy logs a warning and keeps the connection.

Keep all four packages on the same version.

See Troubleshooting.

Mock the outside world. Keep the real app.