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
Verify that service worker blocking is active by checking that navigator.serviceWorker.controller is null in page.evaluate() after navigation
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
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
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
Service worker interception and routing are only supported in Chromium; on Firefox and WebKit, service workers are not inspectable by Playwright even with experimental flags
Setting serviceWorkers: 'block' is strongly recommended when using page.route() for request interception, as an active service worker may handle requests before Playwright's route handler sees them
Experimental service worker network events are not stable API; the environment variable and behavior may change across Playwright versions — pin your Playwright version and test after upgrades
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp