Search code examples
javascriptbrowserservice-workerbackground-sync

How to verify if background sync is supported by the browser?


I am developing an application that uses service workers to cache HTTP requests from a specific endpoint. These requests should be sent to the server using background sync. I know some browsers are not supported, but I would like to warn my users that this feature will not be available. To do this, I need some way of identifying whether or not the browser has background sync support.


Solution

  • if ('serviceWorker' in navigator && 'SyncManager' in window) {
       // service worker stuffs here
    } else {
      console.error('Background sync not supported');
    }