FetchEvent: handled property - Web APIs | MDN

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

Learn how to contribute

This page was last modified on by MDN contributors.