BackgroundFetchEvent
注意:此功能仅在 Service Workers 中可用。
BackgroundFetchEvent 接口是 Background Fetch API 的事件类型,用于在 service worker 全局作用域 上分派的 background fetch 事件。
它是传递给 backgroundfetchclick 事件和 backgroundfetchabort 事件的事件类型。
构造函数
BackgroundFetchEvent()实验性-
创建一个新的
BackgroundFetchEvent对象。通常不使用此构造函数,因为浏览器会自动创建这些对象并将其提供给 background fetch 事件回调。
实例属性
还继承了其父类 ExtendableEvent 的属性。
BackgroundFetchEvent.registration只读 实验性-
返回初始化事件的
BackgroundFetchRegistration。
实例方法
还继承了其父类 ExtendableEvent 的方法。
无。
示例
在此示例中,如果用户点击显示下载进度的用户界面,将打开一个新窗口。通过调用 event.registration 返回当前的 BackgroundFetchRegistration。
js
addEventListener("backgroundfetchclick", (event) => {
const bgFetch = event.registration;
if (bgFetch.result === "success") {
clients.openWindow("/latest-podcasts");
} else {
clients.openWindow("/download-progress");
}
});
规范
| 规范 |
|---|
| Background Fetch # background-fetch-event |
浏览器兼容性
加载中…