public/sw.js
self.onnotificationclick = function (event) {
// return clients.openWindow(event.notification.data);
// This looks to see if the current is already open and
// focuses if it is
event.waitUntil(
clients.matchAll({
type: "window"
}).then(function(clientList) {
for (let i = 0; i < clientList.length; i++) {
let client = clientList[i];
if (client.url == '/' && 'focus' in client)
return client.focus();
}
if (clients.openWindow) {
return clients.openWindow(event.notification.data);
}
})
);
};