ServiceWorkerGlobalScope: periodicsync event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Want more browser support for this feature? Tell us why.
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.
addEventListener("periodicsync", (event) => { })
onperiodicsync = (event) => { }
Event type
A PeriodicSyncEvent. Inherits from Event.
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:
self.onperiodicsync = (event) => {
// …
};
Specifications
| Specification |
|---|
| Web Periodic Background Synchronization> # periodicsync-event> |
| Web Periodic Background Synchronization> # dom-serviceworkerglobalscope-onperiodicsync> |