← All notes

page.route mocks or patches network requests in Playwright

Answer: Playwright can mock an API by fulfilling a page.route handler with a custom response. No requests to that API will be made. You can also perform the request, then fulfill it with a modified response, rather than mocking it entirely. page.routeFromHAR() serves matching responses from a recorded HAR file.

Client API

The page client implements route (URL, handler, optional times) and routeFromHAR.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Playwright docs, Mock APIs, Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation; microsoft/playwright (GitHub), Page.route (playwright-core client), Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Playwright docs, Mock APIs, Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation; microsoft/playwright (GitHub), Page.route (playwright-core client), Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation.

Cite this

Permanent ID: iil:note:cxt9rmtn

iinventedlight. 2026. "page.route mocks or patches network requests in Playwright." iinventedlight Library, iil:note:cxt9rmtn, version of 2026-11-16. https://iinventedlight.com/library/notes/playwright-route-mocking/. License: CC-BY-4.0.

@misc{iil_note_cxt9rmtn,
  author = {{iinventedlight}},
  title = {{page.route mocks or patches network requests in Playwright}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-16},
  url = {https://iinventedlight.com/library/notes/playwright-route-mocking/},
  note = {Permanent ID iil:note:cxt9rmtn. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/playwright-route-mocking.md.