[Webkit-unassigned] [Bug 250454] New: Duplicate requests due to speculative parsing with active service worker

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Jan 11 06:40:05 PST 2023


https://bugs.webkit.org/show_bug.cgi?id=250454

            Bug ID: 250454
           Summary: Duplicate requests due to speculative parsing with
                    active service worker
           Product: WebKit
           Version: Safari Technology Preview
          Hardware: Mac (Apple Silicon)
                OS: macOS 13
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: Service Workers
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: marian.schaub at baqend.com

Overview:
We noticed unexpected behavior when requests issued by the speculative parsing functionality are fetched through a service worker. As far as we can tell it seems like the initial request made by the browser to preload a resource, while being stuck on a blocking script for example, is not collapsed with the actual request made by the DOM parser once the resource is encountered in the HTML. This leads to two requests being handed to the service worker and potentially an unnecessary request to the network in case this scenario is not explicitly handled by the developer.

Steps to Reproduce:
We built a simple example page to showcase the behavior:
https://sw-lifecycle-test.app.baqend.com/speculativeParser/index.html

1. Open https://sw-lifecycle-test.app.baqend.com/speculativeParser/index.html in Safari
2. Open the developer console, go to the Network tab and check "Disable Caches"
3. When reloading the page you should see two image requests (test1.jpeg and test2.jpeg). In both cases the Initiator is line 13 from index.html, which is our synchronous blocking script, indicating this was loaded by the speculative parsing feature.
4. Append "?sw=1" to the url (https://sw-lifecycle-test.app.baqend.com/speculativeParser/index.html?sw=1) and reload the page. This should install a simple service worker.
5. Open a Web Inspector for the installed service worker.
6. Reload once more. Now the service worker is active. Now we see a different behavior: test1.jpeg is present twice in the network tab. One Request with the Initiator set to line 13 as before and one additional request with the initiator pointing two line 14, the actual line of the corresponding image tag in the html. For test2.jpg we see one request as before. This is because the service worker implementation explicitly only fetches the request for test1.jpeg and ignores everything else. In the Web Inspector for the service worker you should see two logs for test1.jpeg and only one log for test2.jpeg.

Note: To uninstall the service worker for debugging you can append "sw=0" as a query parameter to the url.

Actual Results:
In most cases we can observe the described scenario. The DOM parser issues two requests per resources loaded by the speculative parsing functionality. In case the service worker fetches the resource these requests do not seem to be collapsed. There were times where this behavior disappeared after several reloads but after restarting the browser it usually reappeared again.

Expected Results:
The DOM parser matches the existing speculative request with the actual resource and collapses the requests, so no second requests reaches the service worker.

Build Date & Hardware:
Safari TP Release 160 (Safari 16.4, WebKit 18615.1.14.3)

Additional Builds and Platforms:
I could also reproduce this locally in my latest stable Safari (Version 16.1 (18614.2.9.1.12)) on my Mac. We additionally tested this through several different Safari and OS versions via Browserstack and the results were the same.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230111/2c08265e/attachment.htm>


More information about the webkit-unassigned mailing list