Skip to content

[Bug]: Firefox fails to intercept Service Worker registration requests via browserContext.route #38642

@marcospassos

Description

@marcospassos

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

  1. 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>
  1. 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');
});
  1. 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.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions