0

I have a PWA that fetches server data from within the service worker, remembering that the app is installed and running in the background. I currently use the Periodic Background Sync API, but it doesn't work correctly. Does anyone know of an alternative to this API to achieve this with JavaScript?

// Register the sync
try {
    const registration = await window.navigator.serviceWorker.ready;
    registration.periodicSync.unregister('db:update');
    console.log(false);
} catch (error) {
    console.error(error);
}

// Event listener inside Service Worker
sw.addEventListener('periodicsync', async (event) => {
    if (event.tag === 'db:update') {
        event.waitUntil(updateDatabase());
    }
});
Lucas
  • 394
  • 2
  • 13

0 Answers0