Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: using ServiceWorker on localhost over HTTPS (#27863)

Max Schmitt08685a654aeb
diff --git a/tests/library/ignorehttpserrors.spec.ts b/tests/library/ignorehttpserrors.spec.ts
index 5f52b1c940..31a9344cbe 100644
--- a/tests/library/ignorehttpserrors.spec.ts
+++ b/tests/library/ignorehttpserrors.spec.ts
@@ -92,3 +92,31 @@ it('should fail with WebSocket if not ignored', async ({ browser, httpsServer })
expect(value).toBe('Error');
await context.close();
});
+
+it('serviceWorker should intercept document request', async ({ browser, httpsServer, browserName }) => {
+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/27768' });
+ it.fixme(browserName === 'chromium');
+ const context = await browser.newContext({ ignoreHTTPSErrors: true });
+ const page = await context.newPage();
+ await context.route('**/*', route => route.continue());
+ httpsServer.setRoute('/sw.js', (req, res) => {
+ res.setHeader('Content-Type', 'application/javascript');
+ res.end(`
+ self.addEventListener('fetch', event => {
+ event.respondWith(new Response('intercepted'));
+ });
+ self.addEventListener('activate', event => {
+ event.waitUntil(clients.claim());
+ });
+ `);
+ });
+ await page.goto(httpsServer.EMPTY_PAGE);
+ await page.evaluate(async () => {
+ const waitForControllerChange = new Promise(resolve => navigator.serviceWorker.oncontrollerchange = resolve);
+ await navigator.serviceWorker.register('/sw.js');
+ await waitForControllerChange;
+ });
+ await page.reload();
+ expect(await page.textContent('body')).toBe('intercepted');
+ await context.close();
+});