Testing / Playwright Interview questions
How does Playwright implement network interception and request mocking internally?
When a route handler is registered via page.route(), Playwright's browser-side protocol layer subscribes to the browser's own network interception hooks (built on the same low-level machinery that powers DevTools' network panel in Chromium, and equivalent hooks in the patched Firefox/WebKit builds), rather than proxying traffic through an external process.
sequenceDiagram
participant P as Page
participant Pr as Playwright Driver
participant Br as Browser Network Layer
P->>Br: Outgoing request
Br->>Pr: Intercepted, paused
Pr->>Pr: Match against registered route()
Pr-->>Br: fulfill / continue / abort
Br-->>P: Response delivered (real or mocked)
Because interception happens inside the browser's own networking stack before the request leaves the process, Playwright can inspect, modify, or fully replace a response without needing a separate local proxy server or certificate trust setup, which is how tools built around HTTP proxying typically have to work. This also means intercepted requests never actually reach the real network at all when fulfilled with mock data, rather than being sent and then having the response swapped afterward.
More Related questions...