-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Open
Description
Version
1.57.0
Steps to reproduce
When using context.route() to intercept a service worker script request, the route handler is never called in Firefox. The service worker registration fails because the actual file doesn't exist on the server, the interception never happens.
This works correctly in Chromium and WebKit.
Steps to Reproduce
- Create
sw.html:
<!DOCTYPE html>
<html lang="en">
<body>
<script>
function registerServiceWorker() {
return navigator.serviceWorker.register('./sw.js')
.then(() => 'registered')
.catch(e => 'failed: ' + e.message);
}
</script>
</body>
</html>- Run the following test:
test('should intercept service worker registration', async ({ page, context }) => {
await context.route('**/sw.js', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));`
});
});
await page.goto('https://localhost/sw.html');
await expect(page.evaluate(() => registerServiceWorker())).resolves.toEqual('registered');
});- Run with Firefox:
npx playwright test --project=firefox
Expected behavior
The route handler intercepts the sw.js request and fulfills it with the provided script. Service worker registers successfully.
Actual behavior
- The route handler is never called
- Service worker registration fails with:
failed: ServiceWorker script at https://localhost/sw.js for scope https://localhost/ encountered an error during installation. - Works correctly in Chromium and WebKit
Additional context
No response
Environment
System:
OS: macOS 14.4.1
CPU: (11) arm64 Apple M3 Pro
Memory: 76.52 MB / 18.00 GB
npmPackages:
@playwright/test: ^1.57.0 => 1.57.0Metadata
Metadata
Assignees
Labels
No labels