You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*global define:false, console, self, Promise */// https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features// https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/permissions-subscriptions// https://github.com/w3c/ServiceWorker/blob/master/explainer.md// chrome://inspect/#service-workers// https://serviceworke.rs//// Env Setttings//// It's replaced unconditionally to preserve the expected behavior// in programs even if there's ever a native finally.Promise.prototype['finally']=functionfinallyPolyfill(callback){varconstructor=this.constructor;returnthis.then(function(value){returnconstructor.resolve(callback()).then(function(){returnvalue;});},function(reason){returnconstructor.resolve(callback()).then(function(){throwreason;});});};varDEBUG=false;//// Utils// functionlog(msg,obj){console.log('PushWorker',msg,DEBUG ? obj : undefined);}functionpostMessage(msg){if(DEBUG){log("postMessage",msg);}returnself.clients.matchAll().then(function(clients){returnPromise.all(clients.map(function(client){returnclient.postMessage(msg);}));});}functionshowNotification(payload){// Cast has objectif(typeofpayload==='string'){payload={title: payload};}// Clear bad iconsif(typeofpayload.icon==='string'&&payload.icon.indexOf('https://')!==0){deletepayload.icon;}// Clear bad badgeif(typeofpayload.icon==='string'&&payload.badge.indexOf('https://')!==0){deletepayload.badge;}// Force requireInteractionif(typeofpayload.requireInteraction==='undefined'){payload.requireInteraction=true;}if(typeofpayload.actions==='undefined'){// Open/Close payload.datapayload.actions=payload.data ? [{action: 'open',title: 'Open'},{action: 'close',title: 'Dismiss'}// Close (no payload.data)] : [{action: 'close',title: 'Close'}];}// Send via postMessagepostMessage({event: 'push',data: payload});returnself.registration.showNotification(payload.title,{lang: payload.lang||'en',body: payload.body||'Hello!',tag: payload.tag||payload.title,icon: payload.icon,badge: payload.badge,actions: payload.actions,data: payload.data,renotify: !!payload.renotify,requireInteraction: !!payload.requireInteraction,vibrate: payload.vibrate,sound: payload.sound,silent: (payload.silent||(!payload.sound&&!payload.vibrate))});}functionopenUrl(url){returnself.clients.matchAll({includeUncontrolled: true,type: 'window'}).then(function(clientList){varclientListMatchUrl;// Look for a matchif(url){clientListMatchUrl=clientListMatchUrl&&clientListMatchUrl.filter(function(client){returnString(client.url).indexOf(url)===0;});if(clientListMatchUrl&&clientListMatchUrl.length===0){clientListMatchUrl=clientList;}}if(clientList&&clientList.length>0){returnclientList[0].focus();}elseif(url){returnself.clients.openWindow(url);}});}//// Worker//log('Started',self);self.addEventListener('install',function(event){log('Install...',event);event.waitUntil(self.skipWaiting().finally(function(){log('Installed',event);}));});self.addEventListener('activate',function(event){event.waitUntil(self.skipWaiting().then(function(){self.clients.claim();}).finally(function(){log('Activated',event);}));});self.addEventListener('message',function(event){log('Push event received',event);});// Register event listener for the 'push' event.varlastPayload;self.addEventListener('push',function(event){try{varpayload=event.data ? JSON.parse(event.data.text()) : {};// Keep the service worker alive until the notification is created.event.waitUntil(// Show a notification with title 'ServiceWorker Cookbook' and body 'Alea iacta est'.showNotification(payload));}catch(err){log('Push message parse failed',err);}});self.addEventListener('notificationclick',function(event){log('Notification clicked',event);varaction=event.action||'open';if(action==='open'){event.notification.close();event.waitUntil(openUrl(event.notification.data));}elseif(action==='close'){event.notification.close();}},false);self.addEventListener('message',function(event){if(event.data==='PushTest'){log('PushTest...',event);event.waitUntil(showNotification({title: 'Push Notification Test',data: self.location.href}));}});
The text was updated successfully, but these errors were encountered:
manifest.webapp
pushWorker.js
The text was updated successfully, but these errors were encountered: