window.swRegistrationReady = (async () => { const checkPermission = async () => { if(!('serviceWorker' in navigator)) { throw new Error('Service Worker not supported'); } if(!('PushManager' in window)) { throw new Error('Push API not supported'); } if(!('Notification' in window)) { throw new Error('Notification API not supported'); } } const registerSw = async () => { const swRegistration = await navigator.serviceWorker.register('/notification-serviceworker.js'); return swRegistration; } try { await checkPermission(); const registration = await registerSw(); console.log('Service Worker registered'); window.swRegistration = registration; return registration; } catch (err) { console.error(err); throw err; } })();