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

瀏覽器相容性