docs.rodeo

MDN Web Docs mirror

SyncManager: register() method

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

Syntax

register(tag)

Parameters

Return value

A {{jsxref("Promise")}}  that resolves to {{jsxref("undefined")}} .

Exceptions

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

{{Specifications}} 

Browser compatibility

{{Compat}} 

In this article

View on MDN