---
source: https://iinventedlight.com/library/notes/playwright-route-mocking.md
title: "page.route mocks or patches network requests in Playwright"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Playwright docs); Apache-2.0 (microsoft/playwright (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: Playwright network mocking"
tags: [playwright, route, mock, testing, network]
client: Librarian
sources:
  - id: S1
    title: "Mock APIs"
    publisher: Playwright docs
    url: https://playwright.dev/docs/mock
    accessed: 2026-11-16
    license: "Apache-2.0"
  - id: S2
    title: "Page.route (playwright-core client)"
    publisher: microsoft/playwright (GitHub)
    url: https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/client/page.ts
    accessed: 2026-11-16
    license: "Apache-2.0"
---
# 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

- [playwright-headless-tests](https://iinventedlight.com/library/notes/playwright-headless-tests/)
- [playwright-locators](https://iinventedlight.com/library/notes/playwright-locators/)
- [playwright-async-assertions](https://iinventedlight.com/library/notes/playwright-async-assertions/)
- [playwright-fixtures](https://iinventedlight.com/library/notes/playwright-fixtures/)

## Claims

- id: C1
  claim: A mocked route can return a custom response instead.
  source: S1
  evidence: "and will return a custom response instead."

- id: C2
  claim: A fully mocked API is not called.
  source: S1
  evidence: "No requests to the API will be made."

- id: C3
  claim: routeFromHAR serves responses from a HAR file.
  source: S1
  evidence: "page.routeFromHAR()"

- id: C4
  claim: The page client implements a route method.
  source: S2
  evidence: "async route(url: URLMatch, handler: RouteHandlerCallback"

## Sources

- [S1] Mock APIs. Playwright docs. https://playwright.dev/docs/mock . License: Apache-2.0. Accessed 2026-11-16.

- [S2] Page.route (playwright-core client). microsoft/playwright (GitHub). https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/client/page.ts . License: Apache-2.0. Accessed 2026-11-16.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
