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.
- Pick the call
- Choose the reply
- Open the page
- Check the screen
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The director | The test |
| The actor's lines | The mocked response |
| The scene | The page under test |
| Cut, repeat, change a line | Change 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.
| In the trick | What it stands for |
|---|---|
| Empty list | the mocked response |
| Error | the 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
- 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.
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.
- 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.
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.
- 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)
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.
- 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)
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.
- 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.
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.
- 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.
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
- 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.
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.
- 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.
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.
- 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)
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.
- 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)
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.
- 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.
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.
- 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.
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.