navigator.serviceWorker?.addEventListener('message', async function(e){ if (!e.data) return; if (e.data.type === 'SYNC_OUTBOX'){ try{ const items = await DB.allOutbox(); for (const it of items){ try{ const headers = Object.assign({'Content-Type':'application/json'}, Auth && Auth.authHeaders ? Auth.authHeaders() : {}); const res = await fetch((window.API_BASE||'') + it.path, { method: it.method, headers, body: JSON.stringify(it.body) }); if (res.ok){ await DB.clearOutbox(); } }catch(err){ console.warn('sync item failed', err); } } }catch(err){ console.error('process outbox failed', err); } } });