TOPIC 20/6020 MINNOT STARTED

Network interception: route, mock, change and wait for requests

Use page.route to answer, change or block the calls a page makes, and wait for calls with waitForResponse, so every page state can be tested.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a film set where you decide what the other actor says. The director can ask for a cheerful reply, an angry one, or silence. The scene shows how the lead reacts. Nobody needs a real argument to film one.

Daily List is a to-do list app. When the page opens, it asks the server for the task list. Tom wants the empty list, a server error, and a slow answer. Waiting for the real server to break would take all week.

What it is: Playwright is a library that drives a real browser. This slice is network interception. page.route stands between the page and the server. A decides to answer, change, or block the call. The nearest neighbour is a live server. Selenium can sit on the network too, and Cypress has cy.intercept. The idea is the same, and the method names differ.

Why it matters: An empty list may need a fresh account. A server error may need a broken machine. A mock makes each state on purpose, in a fraction of a second, so the test proves the page rather than the partner's uptime.

A film actor is paid to play along. A real server can answer in ways the mock never did. A mocked test shows how the page copes. It does not show that the real server works.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are made up.)

PLAIN WORDS · 4 in this section
playwright
a free Microsoft tool that drives a browser for tests
selenium
A free tool that drives a web browser for checks.
cypress
A free tool that drives a web browser for checks.
uptime
the time a system is working

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Making the page see an empty list, an error or a changed reply, on purpose, and checking what it sent.

  1. Pick the call
  2. Choose the reply
  3. Open the page
  4. Check the screen
Write the lines

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The directorThe test
The actor's linesThe mocked response
The sceneThe page under test
Cut, repeat, change a lineChange the reply and run again

WHERE THIS PICTURE STOPS

  • An actor plays along for pay. A real server may answer in ways the script never did.
  • A film has one script. A test can register several routes.
  • A good scene does not show that the real server works.

HOOK

Write the actor's lines.

REMEMBER IT THIS WAY

A rule of thumb: if you see this, think that.

If the real server will not fail on demand, write the reply yourself: an empty list, an error or a slow answer.

What each part of the trick stands for
In the trickWhat it stands for
Empty listthe mocked response
Errorthe page reacts to a failing server

A made-up reply shows how the page reacts, not how the real server behaves.

TELL A FRIEND

A film set where the director tells the actor what to say back.

OFTEN MIXED UP WITH Stand-ins for other systems: stubs and mocks. The doubles lesson explains stubs and mocks in general. This lesson shows how Playwright makes them for a browser page.

Sources & standards — 6 sources
  1. Market practice

    Network (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes route.continue, route.fulfill and route.abort, blocking images, that the most recently registered matching route takes priority, route.fallback, and that service workers can bypass routing. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  2. Market practice

    Route (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: continue, fallback, fetch, fulfill and headers. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Reference for the route object: fulfill with status, body, headers or json, fetch to perform the real request and change it, continue with changed headers or method, abort with an error code, and fallback to the next handler. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: continue, fallback, fetch, fulfill and headers. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  3. Market practice

    Mock APIs (Playwright documentation) ↗ — Microsoft (Playwright) · Intercepting a request by address pattern and answering it with fixed data; a matching request stalls unless it is continued, fulfilled or aborted (search excerpt, page not opened)

    Describes intercepting a request by Uniform Resource Locator (URL) pattern and fulfilling it with fixed data, and says a matching request stalls unless continued, fulfilled or aborted. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Events (Playwright documentation) ↗ — Microsoft (Playwright) · Start page.waitForResponse before the click that causes the request, then await it afterwards (search excerpt, page not opened)

    Shows page.waitForEvent and page.on, the pattern of starting the wait before the triggering action, and the one-off page.once dialog handler. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  5. Market practice

    Request (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Request methods and postDataJSON. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes request.postDataJSON(), which returns the parsed body of a JSON or form-encoded request, and null when there is no body. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Request methods and postDataJSON. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  6. Market practice

    Response | Playwright ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Response status and request methods. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Response status and request methods · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Response status and request methods. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

PRACTISE AND KEEP

Sources for this topic — 6 sources
  1. Market practice

    Network (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes route.continue, route.fulfill and route.abort, blocking images, that the most recently registered matching route takes priority, route.fallback, and that service workers can bypass routing. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  2. Market practice

    Route (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: continue, fallback, fetch, fulfill and headers. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Reference for the route object: fulfill with status, body, headers or json, fetch to perform the real request and change it, continue with changed headers or method, abort with an error code, and fallback to the next handler. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: continue, fallback, fetch, fulfill and headers. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  3. Market practice

    Mock APIs (Playwright documentation) ↗ — Microsoft (Playwright) · Intercepting a request by address pattern and answering it with fixed data; a matching request stalls unless it is continued, fulfilled or aborted (search excerpt, page not opened)

    Describes intercepting a request by Uniform Resource Locator (URL) pattern and fulfilling it with fixed data, and says a matching request stalls unless continued, fulfilled or aborted. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Events (Playwright documentation) ↗ — Microsoft (Playwright) · Start page.waitForResponse before the click that causes the request, then await it afterwards (search excerpt, page not opened)

    Shows page.waitForEvent and page.on, the pattern of starting the wait before the triggering action, and the one-off page.once dialog handler. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  5. Market practice

    Request (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Request methods and postDataJSON. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes request.postDataJSON(), which returns the parsed body of a JSON or form-encoded request, and null when there is no body. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Request methods and postDataJSON. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  6. Market practice

    Response | Playwright ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Response status and request methods. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Response status and request methods · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Response status and request methods. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.