The fetch()
method of the BackgroundFetchManager
interface initiates a background fetch operation, given one or more URLs or Request
objects.
fetch(id, requests)
fetch(id, requests, options)
The following example shows how to use fetch()
to initiate a background fetch operation. With an active service worker, use the ServiceWorkerRegistration.backgroundFetch
property to access the BackgroundFetchManager
object and call its fetch()
method.
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",
label: "Downloading a show",
},
],
downloadTotal: 60 * 1024 * 1024,
},
);
});