BackgroundFetchManager: phương thức get()

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 get() của giao diện BackgroundFetchManager trả về một Promise được giải quyết bằng BackgroundFetchRegistration gắn với id được cung cấp, hoặc undefined nếu không tìm thấy id.

Cú pháp

js
get(id)

Tham số

id

Mã nhận dạng của một BackgroundFetchRegistration được định nghĩa bằng cách gọi fetch().

Giá trị trả về

Một Promise được giải quyết bằng một BackgroundFetchRegistration hoặc undefined.

Ví dụ

Ví dụ sau cho thấy cách dùng get() để truy xuất một BackgroundFetchRegistration. Khi có một service worker đang hoạt động, hãy dùng ServiceWorkerRegistration.backgroundFetch để truy cập đối tượng BackgroundFetchManager và gọi phương thức get() của nó.

js
navigator.serviceWorker.ready.then(async (swReg) => {
  const bgFetch = await swReg.backgroundFetch.get("my-fetch");
});
// khối mã của tôi

Thông số kỹ thuật

Specification
Background Fetch
# background-fetch-manager-get

Khả năng tương thích trình duyệt