ServiceWorkerGlobalScope: sync event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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 sync event of the ServiceWorkerGlobalScope interface is fired when the page (or worker) that registered the event with the SyncManager is running and as soon as network connectivity is available.

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("sync", (event) => { })

onsync = (event) => { }

Event type

A SyncEvent. Inherits from ExtendableEvent and Event.

Event ExtendableEvent SyncEvent

Event properties

Inherits properties from its ancestor, ExtendableEvent and Event.

SyncEvent.tag Read only

Returns the developer-defined identifier for this SyncEvent.

SyncEvent.lastChance Read only

Returns true if the user agent will not make further synchronization attempts after the current attempt.

Examples

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

js
self.addEventListener("sync", (event) => {
  if (event.tag === "sync-messages") {
    event.waitUntil(sendOutboxMessages());
  }
});

You can also set up the event handler using the onsync property:

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

Specifications

Specification
Web Background Synchronization
# dom-serviceworkerglobalscope-onsync

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
sync event
Chrome – Full support
Chrome 49 (Release date: 2016-03-02)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 24 (Release date: 2014-09-02)
footnote Full support
Safari – No support
Safari
footnote
footnote See bug 182565
Chrome Android – Full support
Chrome Android 49 (Release date: 2016-03-09)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 24 (Release date: 2014-09-10)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 182565
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – No support
WebView Android
footnote
footnote See bug 40449796
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 182565

Legend

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

Full support
Full support
No support
No support
See implementation notes.

See also