From 56080b328a158bd1301a86f45cc1194be95501d2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 25 Jan 2023 15:00:03 +0300 Subject: Web Push: focus existing page on notification click --- src/main/resources/static/sw.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/resources/static/sw.js b/src/main/resources/static/sw.js index 48fe7787..055fcf64 100644 --- a/src/main/resources/static/sw.js +++ b/src/main/resources/static/sw.js @@ -22,8 +22,12 @@ sw.addEventListener('push', function(evt) { } }); sw.addEventListener('notificationclick', function(evt) { - evt.notification.close(); evt.waitUntil( - sw.clients.openWindow('https://juick.com/') + sw.clients.matchAll().then(function(clientList) { + if (clientList.length > 0) { + return clientList[0].focus(); + } + return sw.clients.openWindow('https://juick.com/'); + }) ); }); -- cgit v1.2.3