BackgroundFetchRecord

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

注意:此功能在 Web Workers 中可用。

BackgroundFetchRecord 接口是 Background Fetch API 的一部分,用于表示单个请求和响应。

BackgroundFetchRecordBackgroundFetchRegistration.matchAll() 方法创建,因此该接口没有构造函数。

对于 fetch() 请求的每个资源,都会有一个 BackgroundFetchRecord

实例属性

request 只读 实验性

返回一个 Request 对象。

responseReady 只读 实验性

返回一个解析为 Response 对象的 Promise。

示例

在此示例中,使用 BackgroundFetchRegistration.matchAll() 返回单个 BackgroundFetchRecord。将返回并记录 BackgroundFetchRecord.requestBackgroundFetchRecord.responseReady 到控制台。

js
bgFetch.match("/ep-5.mp3").then(async (record) => {
  if (!record) {
    console.log("No record found");
    return;
  }

  console.log(`Here's the request`, record.request);
  const response = await record.responseReady;
  console.log(`And here's the response`, response);
});

规范

规范
Background Fetch
# background-fetch-record-interface

浏览器兼容性