mdn/content

Service Worker navigation preload sample code error

Open

#43055 opened on Feb 8, 2026

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Markdown (8,900 stars) (22,427 forks)batch import
Content:WebAPIhelp wanted

Description

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