TOPIC 48/6019 MINNOT STARTED

Recorded traffic and WebSockets: HAR files and routeWebSocket

Record the real conversation between the page and the server once, replay it in later runs, and stand in for a live WebSocket feed when a test needs one.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a tape of one phone call. Two people talk. You record the call. Later you play the tape to one of them. The other person does not need to be there.

Tom tests Daily List, a to-do list app. The page asks the server for tasks. Some days the server is slow or down. Tom still wants to see how the page paints an answer.

What it is: Playwright is a free program, made by Microsoft, that drives real web browsers from test code. This topic is one slice of it: saved traffic, and a stand-in for a live feed. A HAR (HTTP Archive, where HTTP (Hypertext Transfer Protocol) names the web protocol) file is a saved record of requests and answers. plays those answers back, so the real server is not asked. A stands in for a WebSocket, a connection that stays open so either side can send news. A mocked response is one answer you supply in place of the server. Do not mix a tape of old answers with a live socket.

Why it matters: a down server blocks that only cares how the page paints. HAR replay gives Tom the same tasks on every run. A WebSocket route lets him push one news message and see the page react, with no live feed.

The tape holds only what was said that day. If the server changes its answers, the file stays old.

Kept simple: a stores traffic. It is not a copy of the whole app.

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

PLAIN WORDS · 2 in this section
playwright
a free Microsoft tool that drives a browser for tests
hypertext
text that links to other pages

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 Testing a page without depending on a slow or changing server, by replaying saved answers and faking a live feed.

  1. Record the call
  2. Replay the tape
  3. Play the server live
  4. Refresh the tape
Record once, replay often, refresh on time

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The tape of the phone callThe saved traffic file
Playing the tape to one personReplaying the saved answers to the page
Playing the part of the other person liveThe WebSocket route
A tape that is years oldA recording that has gone out of date

WHERE THIS PICTURE STOPS

  • A tape holds only what was said that day. A server may talk differently tomorrow.
  • A tape can hold private things. A saved traffic file can hold tokens and names.
  • A person on the phone can be unpredictable. A stand-in sends only what you tell it to, so it can be too tidy.

HOOK

Record once, replay often, refresh on time.

REMEMBER IT THIS WAY

A sequence: the real steps, in order.

Record once, replay often. Before replaying, ask: how old is the tape and does it hold tokens or names?

What each part of the trick stands for
In the trickWhat it stands for
recordsave the traffic file
replayplay the saved answers to the page
old tapeIf the server changes its answers, the file stays old

A stand-in sends only what you tell it to, so it can be too tidy.

TELL A FRIEND

Record the call between app and server once, play it back later, and play the server's part for live news.

OFTEN MIXED UP WITH Network interception: route, mock, change and wait for requests. The mocking lesson covers hand-written answers for single requests. This lesson covers whole recordings and live connections.

Sources & standards — 5 sources
  1. Market practice

    Page (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: pause, route/HAR/WebSocket and waitForResponse. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes routeFromHAR and its notFound and update options. Vendor documentation, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: pause, route/HAR/WebSocket and waitForResponse. 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

    WebSocketRoute (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: message direction, server connection and handler routing. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes routeWebSocket, onMessage, send and connectToServer. Vendor documentation, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: message direction, server connection and handler routing. 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) · Mock API requests with page.route; HAR files can be recorded and replayed; WebSocket routing exists in recent versions (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

    WebSocket API (WebSockets) (Mozilla developer docs) ↗ — Mozilla (developer documentation) · The WebSocket API opens a two-way session between the browser and a server so each side can send messages without a new request (search excerpt, page not opened)

    Per the search excerpt, a WebSocket keeps a live two-way session open between browser and server, so messages can be sent and received without asking each time. · 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

    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.

PRACTISE AND KEEP

Sources for this topic — 5 sources
  1. Market practice

    Page (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: pause, route/HAR/WebSocket and waitForResponse. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes routeFromHAR and its notFound and update options. Vendor documentation, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: pause, route/HAR/WebSocket and waitForResponse. 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

    WebSocketRoute (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: message direction, server connection and handler routing. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes routeWebSocket, onMessage, send and connectToServer. Vendor documentation, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: message direction, server connection and handler routing. 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) · Mock API requests with page.route; HAR files can be recorded and replayed; WebSocket routing exists in recent versions (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

    WebSocket API (WebSockets) (Mozilla developer docs) ↗ — Mozilla (developer documentation) · The WebSocket API opens a two-way session between the browser and a server so each side can send messages without a new request (search excerpt, page not opened)

    Per the search excerpt, a WebSocket keeps a live two-way session open between browser and server, so messages can be sent and received without asking each time. · 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

    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.

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.