start Jabbit Service Worker
Runs pending jobs inside a service worker, so they continue after the last page is closed.
Call this from the top level of the service worker script — a Kotlin/JS or Kotlin/Wasm bundle of its own — with the same description the page uses, because the worker has to be able to build the same workers:
fun main() {
startJabbitServiceWorker {
worker(SyncJob) { SyncWorker(api) }
browser {
periodicSyncTag = "com.example.refresh"
}
}
}The browser { } block must match the page's: the queue is only shared when both sides use the same storage and the same sync tags. That storage must be reachable from a worker, which rules out LocalStorageJabbitStorage.
What the browser actually grants:
sync— one shot, fired when connectivity returns after the app went offline. Chromium only.periodicsync— fired on a cadence the browser chooses, only for an installed app it considers engaging, and only after theperiodic-background-syncpermission is granted. Chromium only.
Neither event fires in Safari or Firefox, where jobs run only while a page is open. Nothing here throws when the events are unavailable; the registrations are simply skipped.
While any page of the app is open the worker stays out of the way and lets the page run the queue, so the same job is never started twice.