Bug 245866 - Safari 16 issuing requests twice with navigationPreload enabled
Summary: Safari 16 issuing requests twice with navigationPreload enabled
Status: RESOLVED DUPLICATE of bug 245788
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: Safari 16
Hardware: iPhone / iPad iOS 16
: P2 Critical
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-09-30 00:16 PDT by Alex
Modified: 2022-10-03 01:25 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2022-09-30 00:16:56 PDT
When I using navigationPreload.enable(), Safari 16.x on macOs and all browser on ios16.x make two requests
Here is my code: 

const uri = 'https://uri';

self.addEventListener('activate', event => {

    event.waitUntil((async () => {
        if (self.registration.navigationPreload) {
            await self.registration.navigationPreload.enable();
        }
    })());
});

self.addEventListener('fetch', (event) => {
    const request = event.request;
    if (request.mode === 'navigate' && request.destination !== 'iframe') {
        event.respondWith((async () => {
            try {
                return await event.preloadResponse || await fetch(request);
            } catch (e) {
                const response = await fetch(uri);
                if (response.ok) {
                    const text = await response.text();
                    const body = decode(text);
                    return new Response(body, { headers: { 'Content-Type': 'text/html' } });
                }
            }
        })());
    }
});

function decode(str) {
    return decodeURIComponent(
        some code
    );
}
Comment 1 Alex 2022-09-30 08:02:50 PDT
this is minimal reproducer

self.addEventListener('activate', event => {
    event.waitUntil((async () => {
        if (self.registration.navigationPreload) {
            await self.registration.navigationPreload.enable();
        }
    })());
});

self.addEventListener('fetch', (event) => {
    const request = event.request;
        event.respondWith((async () => {
            return await event.preloadResponse || await fetch(request);
    })());
});
Comment 2 Radar WebKit Bug Importer 2022-09-30 15:06:33 PDT
<rdar://problem/100639064>
Comment 3 youenn fablet 2022-10-03 01:25:29 PDT
Thanks for the report.
I believe this was fixed in https://bugs.webkit.org/show_bug.cgi?id=245788.
Comment 4 youenn fablet 2022-10-03 01:25:39 PDT

*** This bug has been marked as a duplicate of bug 245788 ***