ServiceWorkerRegistration:backgroundFetch 属性
注意:此功能在 Web Workers 中可用。
ServiceWorkerRegistration 接口的只读属性 backgroundFetch 返回一个指向 BackgroundFetchManager 对象的引用,该对象可用于发起后台抓取操作。
值
一个 BackgroundFetchManager 对象。
示例
发起后台抓取
以下代码访问 backgroundFetch 属性并使用它来发起后台抓取操作。
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",
},
);
// …
}
规范
| 规范 |
|---|
| Background Fetch # dom-serviceworkerregistration-backgroundfetch |
浏览器兼容性
加载中…