ServiceWorkerGlobalScope: sự kiện periodicsync
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
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.
Sự kiện periodicsync của giao diện ServiceWorkerGlobalScope được kích hoạt ở các khoảng thời gian định kỳ, được chỉ định khi đăng ký một PeriodicSyncManager.
Sự kiện này không thể hủy và không nổi bọt.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc thiết lập một thuộc tính trình xử lý sự kiện.
addEventListener("periodicsync", (event) => { })
onperiodicsync = (event) => { }
Loại sự kiện
Một PeriodicSyncEvent. Kế thừa từ Event.
Thuộc tính sự kiện
Kế thừa các thuộc tính từ giao diện tổ tiên, Event.
PeriodicSyncEvent.tagRead only-
Trả về định danh do nhà phát triển định nghĩa cho
PeriodicSyncEventnày. Nhiều tag có thể được sử dụng bởi ứng dụng web để chạy các tác vụ định kỳ khác nhau ở các tần suất khác nhau.
Ví dụ
Ví dụ sau cho thấy cách phản hồi một sự kiện đồng bộ định kỳ trong service worker.
self.addEventListener("periodicsync", (event) => {
if (event.tag === "get-latest-news") {
event.waitUntil(fetchAndCacheLatestNews());
}
});
Bạn cũng có thể thiết lập trình xử lý sự kiện bằng cách sử dụng thuộc tính onperiodicsync:
self.onperiodicsync = (event) => {
// …
};
Đặc tả kỹ thuật
| Thông số kỹ thuật |
|---|
| Web Periodic Background Synchronization> # periodicsync-event> |
| Web Periodic Background Synchronization> # dom-serviceworkerglobalscope-onperiodicsync> |