ServiceWorkerGlobalScope: periodicsync event
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
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.
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
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 |
periodicsync_event |
80 |
80 |
No |
No |
67 |
No |
No |
80 |
No |
57 |
No |
13.0 |
See also