Skip to content

Preserve sec-fetch-dest for passed navigate requests #1803

Open

Description

@ErikWitt

For navigate requests the sec-fetch-dest header is set to document. Once a service worker is introduced that simply forwards the request to the network, the sec-fetch-dest header changes to empty.

There are systems that rely on that header on server side to detect navigate requests and act accordingly. Shopify for example has some language/currency persistence logic that uses it.

Introducing a service worker that forwards requests (e.g. to cache responses for offline handling), breaks functionality.

I would argue that a navigate request from the browser should behave the same when proxied through a service worker. If this cannot be assumed by the developer, it gets very hard to implement service worker without potentially breaking functionality.

To have a reproducable example, here is a test website: https://dm-clone-optimized.app.baqend.com/fetch-dest/

It installs a service worker and when reloading you can see the sec-fetch-dest header being different depending on whether you bypass the service worker or not.

Activity

  1. asutherland commented on Nov 7, 2025

    @asutherland

    I understand the problem here to be that the destination is not propagated by the Request constructor as invoked by fetch(). This probably should be discussed in the fetch spec, although any changes might eventually involve the ServiceWorkers spec.

    whatwg/fetch#1323 seems like it may be the most directly related open issue, with whatwg/fetch#1762 touching on it tangentially. @annevk probably has more useful thoughts.

  2. annevk commented on Nov 20, 2025

    @annevk
    Member

    It's hard as the service worker can replay these responses anywhere. There's no guarantee that a response to a navigation won't be delivered to a <script>. #1395 has some musings, but I think there are even earlier musings on this topic that go a bit more into the challenges.

  3. wanderview commented on Nov 20, 2025

    @wanderview
    Member

    Random brainstorming: The request could track the original navigation internally. If a fetch is made with the request while the original navigation is outstanding, then sec-fetch-dest is passed through. Otherwise is reverts to empty string.

    This would be hard to understand and the request would no longer really be immutable, though.

  4. asutherland commented on Nov 26, 2025

    @asutherland

    One possibility is to alter the optional ServiceWorkerAutoPreload mechanism introduced in #1756 based on the https://github.com/WICG/service-worker-auto-preload proposal that's built on the "race response" mechanism so that 1) sec-fetch-dest gets passed through and 2) it's not optional since the fetch then would be different and webcompat demands all browsers implement that.

  5. yoshisatoyanagisawa commented on Dec 1, 2025

    @yoshisatoyanagisawa
    Collaborator

    Thank you for your thoughts, @asutherland.

    I agree that this is a broader issue for the Fetch specification. It's worth noting that the potential for a service worker to replay a navigation response is not a new risk introduced by features like ServiceWorkerAutoPreload. This possibility has existed since NavigationPreload was introduced.

    This seems to reinforce the ideas discussed in whatwg/fetch#1323, such as adding a new header to indicate to the server that a service worker is involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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