PeriodicSyncManager: register() method
Limited availability
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.
Note: This feature is available in Web Workers.
Phương thức register() của giao diện PeriodicSyncManager đăng ký yêu cầu đồng bộ hóa định kỳ với trình duyệt với tag và tùy chọn được chỉ định. Nó trả về Promise phân giải khi đăng ký hoàn tất.
Cú pháp
register(tag, options)
Tham số
tag-
Định danh
Stringduy nhất. optionsOptional-
Một
Objectchứa dữ liệu tùy chọn sau:minInterval-
Khoảng thời gian tối thiểu, tính bằng mili giây, mà tại đó đồng bộ hóa định kỳ sẽ xảy ra.
Giá trị trả về
Ngoại lệ
InvalidStateErrorDOMException-
Được trả về nếu không có
ServiceWorkerđang hoạt động. NotAllowedErrorDOMException-
Được trả về nếu quyền cho đồng bộ hóa định kỳ nền không được cấp.
InvalidAccessErrorDOMException-
Được trả về nếu cửa sổ đang hoạt động không phải là cửa sổ chính (không thuộc loại
auxiliaryhoặctop-level).
Ví dụ
Hàm bất đồng bộ sau đăng ký một periodic background sync với khoảng thời gian tối thiểu một ngày từ ngữ cảnh duyệt web:
async function registerPeriodicNewsCheck() {
const registration = await navigator.serviceWorker.ready;
try {
await registration.periodicSync.register("fetch-news", {
minInterval: 24 * 60 * 60 * 1000,
});
} catch {
console.log("Periodic Sync could not be registered!");
}
}
Thông số kỹ thuật
| Specification |
|---|
| Web Periodic Background Synchronization> # dom-periodicsyncmanager-register> |