BackgroundFetchRecord
注意:此功能在 Web Workers 中可用。
BackgroundFetchRecord 介面是 Background Fetch API 的一部分,用於表示單個請求和響應。
BackgroundFetchRecord 由 BackgroundFetchRegistration.matchAll() 方法建立,因此該介面沒有建構函式。
對於 fetch() 請求的每個資源,都會有一個 BackgroundFetchRecord。
例項屬性
request只讀 實驗性-
返回一個
Request物件。 responseReady只讀 實驗性-
返回一個解析為
Response物件的 Promise。
示例
在此示例中,使用 BackgroundFetchRegistration.matchAll() 返回單個 BackgroundFetchRecord。將返回並記錄 BackgroundFetchRecord.request 和 BackgroundFetchRecord.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 |
瀏覽器相容性
載入中…