files/en-us/web/api/syncmanager/register/index.md
{{APIRef("Background Sync")}}{{AvailableInWorkers}}
The register() method of the {{domxref("SyncManager")}} interface registers a synchronization event, triggering a {{domxref("ServiceWorkerGlobalScope.sync_event", "sync")}} event inside the associated service worker as soon as network connectivity is available.
register(tag)
tag
tag property of the {{domxref("SyncEvent")}} that gets passed into the service worker's {{domxref("ServiceWorkerGlobalScope.sync_event", "sync")}} event handler.A {{jsxref("Promise")}} that resolves to {{jsxref("undefined")}}.
InvalidStateError {{domxref("DOMException")}}
NotAllowedError {{domxref("DOMException")}}
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}}
{{Compat}}