[Webkit-unassigned] [Bug 259212] clients.openWindow() not opening PWA home screen on iOS and macOS

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Jul 28 00:56:45 PDT 2023


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

Jesper Bendtsen <jesperbendtsen83 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jesperbendtsen83 at gmail.com

--- Comment #1 from Jesper Bendtsen <jesperbendtsen83 at gmail.com> ---
I have the same problem. There must be something wrong, it just opens the installed app! I tried a lot of combinations similar to your implementation.

Tested on iPhone iOS 16.6 and iPad iOS 16.6. When the app is closed, in the background and foreground.

The last thing I've experienced is super weird and doesn't make sense:

I copied the Angular service worker file ngsw-worker.js and tried their implementation "navigateLastFocusedOrOpen"

// In event.waitUntil
let matchingClient = await this.getLastFocusedMatchingClient(this.scope);

if (matchingClient) {
    matchingClient = await matchingClient.navigate(urlToOpen);
    await(matchingClient == null ? void 0 : matchingClient.focus());
} else {
    await this.scope.clients.openWindow(urlToOpen);
}

// Angular function
async getLastFocusedMatchingClient(scope2) {
    const windowClients = await scope2.clients.matchAll({ type: "window" });
    return windowClients[0];
}

It just opens the installed app (works on my PC with Chrome), but then I inserted some debug code in the top of event.waitUntil and now it works 95% of the time, it goes to the relative url, both when the app is closed, in the background and foreground! If I remove the debug code, it just open the installed app again!

// Debug
const clientStates = await this.scope.clients
    .matchAll({
        includeUncontrolled: true, type: 'window'
    })
    .then((clientList) => {
        let clientStates = [];

        for (const client of clientList) {
            clientStates.push({
                visibilityState: client.visibilityState,
                focused: client.focused,
            });
        }

        return clientStates;
    });

await fetch(this.scope.registration.scope + '/api/web-push/notificationclick', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        onActionClick: onActionClick,
        urlToOpen: urlToOpen,
        clientStates: clientStates
    }),
}).catch(error => {
    console.error(error);
});

-- 
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/20230728/3693c0d0/attachment.htm>


More information about the webkit-unassigned mailing list