SyncManager: register() method
Note: This feature is available in Web Workers.
The register()
method of the SyncManager
interface registers a synchronization event, triggering a sync
event inside the associated service worker as soon as network connectivity is available.
Syntax
js
register(tag)
Parameters
Return value
Exceptions
InvalidStateError
DOMException
-
Thrown if current service worker is not active.
NotAllowedError
DOMException
-
Thrown if background sync has been disabled by the user.
Examples
The following asynchronous function registers a background sync from a browsing context:
js
async function syncMessagesLater() {
const registration = await navigator.serviceWorker.ready;
try {
await registration.sync.register("sync-messages");
} catch {
console.log("Background Sync could not be registered!");
}
}
Specifications
Specification |
---|
Web Background Synchronization # dom-syncmanager-register |
Browser compatibility
BCD tables only load in the browser