self.addEventListener('install', function(e){ self.skipWaiting(); }); self.addEventListener('activate', function(e){ self.clients.claim(); }); self.addEventListener('fetch', function(e){ if (e.request.method !== 'GET') return; e.respondWith(fetch(e.request).catch(()=>caches.match(e.request))); }); self.addEventListener('sync', function(e){ if (e.tag && e.tag.startsWith('atulya-sync-')){ e.waitUntil(self.clients.matchAll().then(all=>all.map(c=>c.postMessage({type:'SYNC_OUTBOX'})))); } }); self.addEventListener('message', function(e){ if (e.data && e.data.type === 'TRIGGER_SYNC'){ self.registration.sync.register('atulya-sync-' + Date.now()).catch(()=>{}); } });