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.
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.