MDN Web Docs

Value

A Promise that is pending while the event has not been handled, and fulfilled once it has.

Examples

js

addEventListener("fetch", (event) => {
  event.respondWith(
    (async function () {
      const response = await doCalculateAResponse(event.request);
      event.waitUntil(
        (async function () {
          await doSomeAsyncStuff(); // optional
          // Wait for the event to be consumed by the browser
          await event.handled;
          return doFinalStuff(); // Finalize AFTER the event has been consumed
        })(),
      );
      return response;
    })(),
  );
});

Specifications

Specification
Service Workers Nightly
# dom-fetchevent-handled

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗