Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/assets/serviceworkers/fetchdummy/sw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
self.addEventListener('fetch', event => {
if (event.request.url.endsWith('/headers')) {
event.respondWith(new Response(JSON.stringify(Object.fromEntries(event.request.headers))));
return;
}
if (event.request.url.endsWith('.html') || event.request.url.includes('passthrough')) {
event.respondWith(fetch(event.request));
return;
Expand Down
18 changes: 17 additions & 1 deletion tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ it('RO-151 should work with navigation @smoke', async ({ page, server }) => {
expect(requests.get('style.css').isNavigationRequest()).toBe(false);
});

it('RO-152 should intercept after a service worker', async ({ page, server, browserName, isAndroid, isBidi }) => {
it('RO-152 should intercept after a service worker', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/41932' },
}, async ({ page, server, browserName, isAndroid, isBidi, isFrozenWebkit }) => {
it.skip(isAndroid);

await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html');
Expand All @@ -59,6 +61,20 @@ it('RO-152 should intercept after a service worker', async ({ page, server, brow
const swResponse2 = await page.evaluate(() => window['fetchDummy']('foo'));
expect(swResponse2).toBe('responseFromServiceWorker:foo');

// Frozen WebKit predates the header preservation fix.
if (!isFrozenWebkit) {
const headers = {
'cache-control': 'max-age=12345',
'accept-language': 'fr-CH',
'accept': 'application/custom',
};
const receivedHeaders = await page.evaluate(async headers => {
const response = await fetch('headers', { headers });
return response.json();
}, headers);
expect(receivedHeaders).toMatchObject(headers);
}

// Page route is not applied to service worker initiated fetch.
const nonInterceptedResponse = await page.evaluate(() => window['fetchDummy']('passthrough'));
expect(nonInterceptedResponse).toBe('FAILURE: Not Found');
Expand Down
Loading