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โ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
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 SyncisBackgroundFetchAvailable()โ feature check for Background FetchregisterBackgroundSync(tag)โ registers a background sync taskregisterBackgroundFetch(tag, urls, options?)โ registers a background fetch task
See the API reference for full signatures.