files/en-us/web/api/backgroundfetchregistration/index.md
{{APIRef("Background Fetch API")}}{{SeeCompatTable}}{{AvailableInWorkers}}
The BackgroundFetchRegistration interface of the {{domxref('Background Fetch API','','',' ')}} represents an individual background fetch.
A BackgroundFetchRegistration instance is returned by the {{domxref("BackgroundFetchManager.fetch()")}} or {{domxref("BackgroundFetchManager.get()")}} methods, and therefore there has no constructor.
{{InheritanceDiagram}}
Also inherits properties from its parent, {{domxref("EventTarget")}}.
0.0.0."success" or "failure"."", "aborted", "bad-status", "fetch-error", "quota-exceeded", "download-total-exceeded".recordsAvailable flag is set.Also inherits methods from its parent, {{domxref("EventTarget")}}.
true if the fetch was successfully aborted.Also inherits events from its parent, {{domxref("EventTarget")}}.
Listen to these events using {{domxref("EventTarget.addEventListener", "addEventListener()")}} or by assigning an event listener to the oneventname property of this interface.
The following code creates a BackGroundFetchRegistration as bgFetch, with an id of "my-fetch".
navigator.serviceWorker.ready.then(async (swReg) => {
const bgFetch = await swReg.backgroundFetch.fetch(
"my-fetch",
["/ep-5.mp3", "ep-5-artwork.jpg"],
{
title: "Episode 5: Interesting things.",
icons: [
{
sizes: "300x300",
src: "/ep-5-icon.png",
type: "image/png",
},
],
downloadTotal: 60 * 1024 * 1024,
},
);
});
Logging the {{domxref("BackgroundFetchRegistration.id","id")}} to the console returns "my-fetch".
console.log(bgFetch.id); // "my-fetch"
The {{domxref("BackgroundFetchRegistration.match","match()")}} method can be used to find a particular {{domxref("BackgroundFetchRecord")}} from those that are part of the registration.
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);
});
{{Specifications}}
{{Compat}}