Skip to main content

backgroundtasks

Registers Background Sync and Background Fetch tasks through a service worker registration.

Import: @rtorcato/browser-common/backgroundtasks

๐Ÿ“– MDN: Background Synchronization API

Background Sync and Background Fetch are Chromium-only and require an active service worker โ€” registerBackgroundSync/registerBackgroundFetch resolve to undefined silently when unsupported or no service worker is registered, they don't throw.

Browser supportโ€‹

APIChromeEdgeFirefoxSafariiOS SafariBaseline
SyncManagerโœ… 49+โœ… 79+โŒโŒโŒLimited

โœ… supported ยท โ— partial ยท โŒ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: SyncManager

Exampleโ€‹

import {
isBackgroundSyncAvailable,
registerBackgroundSync,
registerBackgroundFetch,
} from '@rtorcato/browser-common/backgroundtasks'

if (isBackgroundSyncAvailable()) {
await registerBackgroundSync('sync-outbox')
}

await registerBackgroundFetch('media', ['/video.mp4'], { title: 'Video' })

Exportsโ€‹

  • isBackgroundSyncAvailable() โ€” feature check for Background Sync
  • isBackgroundFetchAvailable() โ€” feature check for Background Fetch
  • registerBackgroundSync(tag) โ€” registers a background sync task
  • registerBackgroundFetch(tag, urls, options?) โ€” registers a background fetch task

See the API reference for full signatures.