Open PWA/website when web push notification is clicked

1.2k views Asked by At

I have a simple PWA which sends web push notifications to Android users. I want the PWA to be opened (either the installed app, or whichever browser receives the notification), and following the method outlined in this guide, I've ended up with the following event listener:

self.addEventListener('notificationclick', function(event) {
    const clickedNotification = event.notification;
    clickedNotification.close();
    const promiseChain = clients.openWindow('/');
    event.waitUntil(promiseChain);
});

The listener is invoked and the notification is indeed closed, but the website is generally not opened: If I click the notification from the lock screen, the screen unlocks but in most cases, it then goes on to simply display the Android home screen rather than the app (and I haven't figured out what causes the inconsistency). This is on Chrome 80.0.3987.149 on Android 10.

Should I be doing something else than the above?

0

There are 0 answers