arrow-left Back to topicQuizService WorkersCheck yourself1.When should you reach for service worker testing APIs instead of page.route()?For every network mock — service worker APIs are more powerful.Only when the service worker itself is the subject of the test: PWA offline behavior, caching strategies, or worker-owned network routing.Whenever you need to intercept HTTPS requests.Only in CI environments where a real server is unavailable.2.How do you disable service workers for all tests in a project?Set serviceWorkers: 'block' in the use section of playwright.config.ts.Pass --disable-service-workers to the CLI.Call context.blockServiceWorkers() before each test.Set ignoreServiceWorkers: true in the browser launch options.3.Which event on the browser context fires when a page registers a service worker?'workerregistered''worker''serviceworker''serviceWorkerActivated'4.After navigating to a page with a service worker, how do you wait until the worker actually controls the page before running assertions?Call serviceWorker.waitUntilActive() on the worker object.Listen for the controllerchange event on navigator.serviceWorker inside page.evaluate().Wait for context.waitForEvent('load').Check serviceWorker.state === 'activated' in a polling loop.5.Where are service-worker network requests reported in Playwright — on the page or on the browserContext?On the page object, the same as all other requests.On the browserContext object.On a dedicated ServiceWorker event emitter.They are not reported anywhere — you must intercept them in the worker script.6.What happens when you call request.frame() on a request that was made by a service worker?It returns null.It returns the main frame of the page.It throws an error.It returns the service worker as a special frame.7.How do you route only service-worker-originated requests while letting regular page requests pass through?Use page.route('**', ...) and check request.isServiceWorker().Use context.route('**', ...), check request.serviceWorker() and route.fulfill() for worker requests, route.continue() for others.Use serviceWorker.route('**', ...) — there is a dedicated routing API on the worker object.Register a fetch event handler inside the service worker script itself.8.What is the correct way to set up the serviceworker event listener to avoid a race condition where the worker registers before the listener is attached?Call context.on('serviceworker', ...) after page.goto() completes.Create the promise with context.waitForEvent('serviceworker') before calling page.goto(), then await the promise after.Use a beforeAll hook to register the listener once for the whole suite.Add a page.waitForTimeout(1000) after page.goto() to give the worker time to register.Submit answersarrow-left PreviousExtensibilityChrome extensionsNext arrow-right