MDN self-hosted library · e01.org

ServiceWorkerGlobalScope: periodicsync event

Periodic Background Syncservice

Periodic Background Syncservice

The periodicsync event of the ServiceWorkerGlobalScope interface is fired at timed intervals, specified when registering a PeriodicSyncManager.

This event is not cancelable and does not bubble.

Syntax

Use the event name in addEventListener():

addEventListener("periodicsync", (event) => { })

Alternatively, assign to the event handler property of the interface:

onperiodicsync = (event) => { }

Event type

A PeriodicSyncEvent. Inherits from Event.

PeriodicSyncEvent

Examples

The following example shows how to respond to a periodic sync event in the service worker.

self.addEventListener("periodicsync", (event) => {
  if (event.tag === "get-latest-news") {
    event.waitUntil(fetchAndCacheLatestNews());
  }
});

You can also set up the event handler using the onperiodicsync property (but note that this replaces other event listeners added using onperiodicsync, if any):

self.onperiodicsync = (event) => {
  // …
};

Specifications

Browser compatibility

See also