web api instance method
SyncManager: register() method
Available in 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
register(tag)
Parameters
tag
Return value
A Promise that resolves to undefined.
Exceptions
InvalidStateErrorDOMException- : Thrown if current service worker is not active.
NotAllowedErrorDOMException- : Thrown if background sync has been disabled by the user.
Examples
The following asynchronous function registers a background sync from a browsing context:
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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.