Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. ExtendableEvent
  4. waitUntil()

ExtendableEvent: waitUntil() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨April 2018⁩.

Note: This feature is only available inService Workers.

TheExtendableEvent.waitUntil()method tells the event dispatcher that work is ongoing. It can also be used to detectwhether that work was successful. In service workers,waitUntil() tellsthe browser that work is ongoing until the promise settles, and it shouldn't terminatethe service worker if it wants that work to complete.

Theinstall events inservice workers usewaitUntil() to hold the service worker intheinstalling phase until taskscomplete. If the promise passed towaitUntil() rejects, the install isconsidered a failure, and the installing service worker is discarded. This is primarilyused to ensure that a service worker is not considered installed until all of the corecaches it depends on are successfully populated.

Theactivate events inservice workers usewaitUntil() to buffer functional events such asfetch andpush until the promise passed towaitUntil() settles. Thisgives the service worker time to update database schemas and delete outdatedcaches, so other events can rely on a completely upgraded state.

ThewaitUntil() method must be initially called within the event callback,but after that it can be called multiple times, until all the promises passed to itsettle.

Syntax

js
waitUntil(promise)

Parameters

promise

APromise that extends the lifetime of the event.

Return value

None (undefined).

Examples

UsingwaitUntil() within a service worker'sinstall event:

js
addEventListener("install", (event) => {  const preCache = async () => {    const cache = await caches.open("static-v1");    return cache.addAll(["/", "/about/", "/static/styles.css"]);  };  event.waitUntil(preCache());});

Specifications

Specification
Service Workers Nightly
# dom-extendableevent-waituntil

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp