sS hRegisterServiceWorker(S workerURL) { ret hjs(replaceDollarVars(javaScript_hashLocalIdentifiers("serviceWorker_", [[ const #check = () => { if (!('serviceWorker' in navigator)) { throw new Error('No Service Worker support!') } if (!('PushManager' in window)) { throw new Error('No Push API Support!') } }; const #requestNotificationPermission = async () => { const permission = await window.Notification.requestPermission() // value of permission can be 'granted', 'default', 'denied' // granted: user has accepted the request // default: user has dismissed the notification permission popup by clicking on x // denied: user has denied the request. if (permission !== 'granted') { throw new Error('Permission not granted for Notification') } }; const #registerServiceWorker = async () => { console.log("registerServiceWorker " + $workerURL); const swRegistration = await navigator.serviceWorker.register($workerURL, {scope: '/'}); return swRegistration; }; const #showLocalNotification = (title, body, swRegistration) => { swRegistration.showNotification(title, { body }); } const #main = async () => { check(); const swRegistration = await registerServiceWorker(); console.log("Service worker registered: " + swRegistration); const permission = await requestNotificationPermission(); console.log("Notification permission: " + permission); //showLocalNotification('Demo notification', 'Hello user', swRegistration); }; main(); ]]), workerURL := jsQuote(workerURL)); }