ServiceWorkerGlobalScope: periodicsync event

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is only available in Service Workers.

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 methods like addEventListener(), or set an event handler property.

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

onperiodicsync = (event) => {};

Event type

Event properties

Inherits properties from its ancestor, Event.

PeriodicSyncEvent.tag Read only

Returns the developer-defined identifier for this PeriodicSyncEvent. Multiple tags can be used by the web app to run different periodic tasks at different frequencies.

Examples

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

js
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:

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

Specifications

Specification
Web Periodic Background Synchronization
# periodicsync-event
Web Periodic Background Synchronization
# dom-serviceworkerglobalscope-onperiodicsync

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
periodicsync event
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

See also