ServiceWorkerRegistration: thuộc tính backgroundFetch

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.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Thuộc tính chỉ đọc backgroundFetch của giao diện ServiceWorkerRegistration trả về một tham chiếu đến đối tượng BackgroundFetchManager, có thể được sử dụng để khởi tạo các hoạt động fetch nền.

Giá trị

Một đối tượng BackgroundFetchManager.

Ví dụ

Khởi tạo một background fetch

Mã sau truy cập thuộc tính backgroundFetch và sử dụng nó để khởi tạo một hoạt động fetch nền.

js
// main.js
async function requestBackgroundFetch(movieData) {
  const swRegistration = await navigator.serviceWorker.ready;
  const fetchRegistration = await swRegistration.backgroundFetch.fetch(
    "download-movie",
    ["/my-movie-part-1.webm", "/my-movie-part-2.webm"],
    {
      icons: movieIcons,
      title: "Downloading my movie",
      downloadTotal: 60 * 1024 * 1024,
      label: "Downloading a show",
    },
  );
  // …
}

Đặc tả kỹ thuật

Specification
Background Fetch
# dom-serviceworkerregistration-backgroundfetch

Tương thích trình duyệt