dom / latest / serviceworkerglobalscope / sync_event.html /

ServiceWorkerGlobalScope: sync event

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.

addEventListener('sync', event => { });

onsync = event => { };

Event type

Event properties

Inherits properties from its ancestor, 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.

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

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

self.onsync = event => {
  ...
};

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
sync_event
49
79
No
No
36
No
49
49
No
36
No
5.0
SyncEvent
49
79
No
No
36
No
49
49
No
36
No
5.0
lastChance
49
79
No
No
36
No
49
49
No
36
No
5.0
tag
49
79
No
No
36
No
49
49
No
36
No
5.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/sync_event