mdn/content

Service Worker navigation preload sample code error

Geschlossen

#43.055 geöffnet am 08.02.2026

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Markdown (23.184 Forks)batch import
Content:WebAPIhelp wanted

Repository-Metriken

Stars
 (10.905 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 7T 3h) (147 gemergte PRs in 30 T)

Beschreibung

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers

What specific section or headline is this issue about?

Service Worker navigation preload: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#service_worker_navigation_preload

What information was incorrect, unhelpful, or incomplete?

The code...

const responseFromCache = await caches.match(request);
  if (responseFromCache) {
    return responseFromCache;
  }
const preloadResponse = await preloadResponsePromise;
  if (preloadResponse) {
    console.info("using preload response", preloadResponse);
    event.waitUntil(putInCache(request, preloadResponse.clone()));
    return preloadResponse;
  }

... causes chrome console to display the following error: "The service worker navigation preload request was cancelled before 'preloadResponse' settled. If you intend to use 'preloadResponse', use waitUntil() or respondWith() to wait for the promise to settle."

This can be corrected by changing the first block...

if (responseFromCache) {
  // Wait for preload to settle to avoid cancellation warning
  preloadResponsePromise.catch(() => {}); // Ignore errors
  return responseFromCache;
}

What did you expect to see?

N/A

Do you have any supporting links, references, or citations?

Anthropic Claude, given the code and the error, provided the solution.

Do you have anything more you want to share?

No response

MDN metadata

Contributor Guide