decide between raw cdp fetch-domain request interception and playwright's page.route() for mocking network requests

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. default to page.route()/context.route() for request mocking in Playwright tests, since it is the documented, cross-browser (Chromium/Firefox/WebKit) API with route.fulfill()/route.continue()/route.abort()
  2. reach for a raw CDPSession and the Fetch domain only when a Chromium-specific capability is needed that route() does not expose, such as low-level response body streaming or auth challenge handling outside Playwright's model
  3. if using CDP directly, call session.send('Fetch.enable') with the relevant request patterns and handle Fetch.requestPaused events manually
  4. weigh that CDP-based interception ties the test to Chromium only, while route() keeps the test portable across browser engines
  5. prefer combining both only when necessary -- e.g. route() for behavior assertions and a scoped CDP session for one-off protocol-level debugging

Known gotchas

Related routes

Intercept, inspect, and mock network requests in Playwright tests
playwright.dev · 5 steps · unrated
Intercept and mock WebSocket messages in Playwright using page.routeWebSocket()
playwright.dev · 5 steps · unrated
Intercept and rewrite outbound API responses in a Playwright test using route.fulfill() with a custom JSON body
playwright.dev · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans