admin管理员组

文章数量:1201991

I have a PWA that should open a specific page when a notification is clicked. Right now I'm testing on iPhone 18.1.1, and it works in all scenarios except when the PWA is closed (swiped away). When the PWA is closed and I click on the notification, the PWA navigates to the base URL that I used when saving the app on the home screen. When the PWA is NOT closed and I click on the notification, the PWA navigates to the specified URL.

I have tried different implementations from different threads I've found on SO and other sites. None of the implementations have caused the PWA to navigate to the specific url when being closed.

Here is a minimal example of the code I'm using to open a window when the PWA is not already opened. In this examples there are two strategies I have tried (I'm not using them at the same time). I have tried putting event.waitUntil() around each strategies call.

self.addEventListener("notificationclick", function (event) {

event.preventDefault();

let url = "https://origin/specific-path";

event.notification.close();

event.waitUntil(
    self.clients.matchAll({ type: "window", includeUncontrolled: true })
        .then((clientsArray) => {

            // Code for navigating an open PWA omitted.

            // One of the tried strategies.
            return clients
                .openWindow(notificationURL)
                .then(function (newClient) {
                    newClient.navigate(notificationURL);
                });

            // Another of the tried strategies.
            self.clients
                .openWindow(url)
                .then((windowClient) => (windowClient ? windowClient.focus() : null));
        })
);

});

Note: I think this issue is separate from the other threads here because this is specifically about opening a specific url when the PWA is closed.

本文标签: