As of Safari 15.5/Webkit 613.2.7, when a service worker has just moved from "idle" to "active", any fetch requests it makes will lack custom headers and referrer. I am able to reproduce this problem consistently via installing this sandbox service worker: ``` self.addEventListener("fetch", (event) => { const newRequest = new Request(event.request, { headers: { "X-My-Custom-Header": "1" }, }); event.respondWith(fetch(newRequest)); }); ``` And then checking the contents of the "$_SERVER" variable on my my PHP server (or whatever equivalent you use): ``` [HTTP_HOST] => <my test server url> [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_COOKIE] => <omitted, but looks good> [HTTP_USER_AGENT] => Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1 [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.9 [HTTP_ACCEPT_ENCODING] => gzip, deflate, br [HTTP_CONNECTION] => keep-alive [HTTP_REFERER] => ``` And you can see that `HTTP_X_MY_CUSTOM_HEADER` is missing. To reproduce: 1. Install the sandbox service worker I posted above. 2. Load a page and see that the custom header and referrer are sent correctly in a network request. 3. Allow the service worker to go to the idle state. Practically, this looks like closing the test domain's tab and visiting another site for roughly 10 seconds. You can check the `Develop > Service Workers` drop-down menu to see if the service worker has been idled; if it has, it will be missing from this list. 4. Re-visit your test domain and see that the new request is now missing the custom header and referrer. 5. Re-load the page and see that a page request from an active and started service worker always contains the custom header and referrer. Thanks for your help, and let me know whatever other info you need to debug. This is a blocking bug for Etsy's use of service workers.
Note also that this issue is not present in any other browser that our company has been able to detect.
We're seeing data in production that puts this bug back as far as 13.1.2.
<rdar://problem/97616866>
We might be reusing the preload we might be doing as the service worker is not active. We should probably not since we are trying to fetch newRequest and not event.request.
Pull request: https://github.com/WebKit/WebKit/pull/6624
Committed 257110@main (157a46485c50): <https://commits.webkit.org/257110@main> Reviewed commits have been landed. Closing PR #6624 and removing active labels.