Test and block service workers in Playwright to isolate network behavior

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

Steps

  1. To prevent service workers from intercepting requests during tests, set serviceWorkers: 'block' in your browser context options or in the use block of playwright.config.ts
  2. Verify that service worker blocking is active by checking that navigator.serviceWorker.controller is null in page.evaluate() after navigation
  3. To test the service worker itself (Chromium only), enable experimental service worker network events by setting the PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS=1 environment variable before running tests
  4. Assert offline behavior by combining page.route('**/*', route => route.abort()) with a navigation to simulate network failure and verifying that the page displays its offline fallback
  5. For testing the install and activate lifecycle, navigate to the page normally and listen for the page.serviceWorkers event to get a reference to the registered ServiceWorker object

Known gotchas

Related routes

Intercept, inspect, and mock network requests in Playwright tests
playwright.dev · 5 steps · unrated
Capture and analyze network requests during a Playwright test using request and response events
playwright.dev · 5 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