[w3c/ServiceWorker] Only add the Service-Worker header to the top-level script request (PR #1864)

Closes #1574.

In the Update algorithm's perform the fetch hook, the `Service-Worker: script` header was appended before the isTopLevel check. That meant modules statically imported by a module service worker were also fetched with it. Because the header isn't CORS-safelisted, a cross-origin static import needed a preflight and failed unless the server allowed `Service-Worker` in `Access-Control-Allow-Headers`.

This moves the append to after the isTopLevel check, as @wanderview suggested and @monica-ch confirmed in triage, so only the top-level script request carries the header. That matches `importScripts()`, which has never sent it, and keeps the header useful for identifying service worker root scripts in server logs. A note explains the behavior.

Not in this PR: @jakearchibald's points about `updateViaCache: "imports"` and byte-for-byte checks for module imports. Those can go in a separate issue, as the thread suggested.

Built locally with Bikeshed 8.0.3 with no warnings or errors, the same as before the change.

The following tasks have been completed:

- [ ] Modified Web platform tests (link to follow)

Implementation commitment:

- [ ] WebKit: not yet tested
- [ ] Chromium: no change needed; Chrome 156 already omits the header on static imports and passes the new test
- [ ] Gecko: no change needed; Firefox 159 already omits the header on static imports and passes the new test


<!--
    This comment and the below content is programmatically generated.
    You may add a comma-separated list of anchors you'd like a
    direct link to below (e.g. #idl-serializers, #idl-sequence):

    Don't remove this comment or modify anything below this line.
    If you don't want a preview generated for this pull request,
    just replace the whole of this comment's content by "no preview"
    and remove what's below.
-->
***
<a href="https://pr-preview.w3.org/ikram1201/ServiceWorker/pull/1864.html" title="Last updated on Nov 24, 2026, 4:30 PM UTC (205cca5)">Preview</a> | <a href="https://pr-preview.w3.org/w3c/ServiceWorker/1864/05701db...ikram1201:205cca5.html" title="Last updated on Nov 24, 2026, 4:30 PM UTC (205cca5)">Diff</a>
You can view, comment on, or merge this pull request online at:

  https://github.com/w3c/ServiceWorker/pull/1864

-- Commit Summary --

  * Only add the Service-Worker header to the top-level script request

-- File Changes --

    M index.bs (10)

-- Patch Links --

https://github.com/w3c/ServiceWorker/pull/1864.patch
https://github.com/w3c/ServiceWorker/pull/1864.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/pull/1864
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/pull/1864@github.com>

Received on Tuesday, 24 November 2026 16:31:23 UTC