Periodic Background Syncservice
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 EventTarget/addEventListener:
addEventListener("periodicsync", (event) => { })
Alternatively, assign to the event handler property of the interface:
onperiodicsync = (event) => { }
Event type
A PeriodicSyncEvent. Inherits from Event.
PeriodicSyncEvent
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 (but note that this replaces other event listeners added using onperiodicsync, if any):
self.onperiodicsync = (event) => {
// …
};
Specifications
Browser compatibility
See also
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
