ServiceWorkerGlobalScope: sync event
Draft: This page is not complete.
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.
| Bubbles | No |
|---|---|
| Cancelable | No |
| Interface | SyncEvent |
| Event handler property | ServiceWorkerGlobalScope.onsync |
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 ServiceWorkerGlobalScope.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 |
? |
No |
No |
49 |
No |
? |
No |
5.0 |
SyncEvent |
49 |
79 |
No |
No |
? |
No |
No |
49 |
No |
? |
No |
5.0 |
lastChance |
49 |
79 |
No |
No |
? |
No |
No |
49 |
No |
? |
No |
5.0 |
tag |
49 |
79 |
No |
No |
? |
No |
No |
49 |
No |
? |
No |
5.0 |
See also
- Richer offline experiences with the Periodic Background Sync API
- A Periodic Background Sync demo app
© 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