const Outbox = (function(){ async function enqueue(method,path,body){ await DB.addOutbox({method,path,body}); if (navigator.serviceWorker && 'sync' in navigator.serviceWorker){ try{ const reg = await navigator.serviceWorker.ready; await reg.sync.register('atulya-sync-' + Date.now()); }catch(e){ console.warn('sync failed', e);} } } async function flush(){ if (navigator.serviceWorker && navigator.serviceWorker.controller){ navigator.serviceWorker.controller.postMessage({type:'TRIGGER_SYNC'}); } } return { enqueue, flush }; })(); window.Outbox = Outbox;