/// /// /// var sw = /** @type {ServiceWorkerGlobalScope & typeof self} */ (self); sw.addEventListener('install', function() { sw.skipWaiting(); }); sw.addEventListener('activate', function() { sw.clients.claim(); }); sw.addEventListener('push', function(evt) { if (evt.data) { const data = evt.data.json(); console.log('Push', data); if (data.body) { sw.registration.showNotification(data.title, { body: data.body, icon: data.custom.message.user.avatar }); } } }); sw.addEventListener('notificationclick', function(evt) { evt.waitUntil( sw.clients.matchAll().then(function(clientList) { if (clientList.length > 0) { return clientList[0].focus(); } return sw.clients.openWindow('https://juick.com/'); }) ); });