Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

ExtendableEvent.waitUntil()

Cette traduction est incomplète. Aidez à traduire cet article depuis l'anglais.

The ExtendableEvent.waitUntil() method extends the lifetime of the event. When called in an EventHandler associated to the install event, it delays treating the installing worker as installed until the passed Promise resolves successfully. This is primarily used to ensure that a service worker is not considered installed until all of the core caches it depends on are populated.

When called in an EventHandler associated to the activate event, it delays treating the active worker as activated until the passed Promise resolves successfully. This is primarily used to ensure that any functional events are not dispatched to the ServiceWorkerGlobalScope object until it upgrades database schemas and deletes the outdated Cache entries.

When the method runs, if the Promise is resolved, nothing happens. If the Promise is rejected, the state of the installing or active worker is set to redundant.

If waitUntil() is called outside of the ExtendableEvent handler, the browser should throw an InvalidStateError; note also that multiple calls will stack up, and the resulting promises will be added to the list of extend lifetime promises.

Note: The behaviour described in the above paragraph was fixed in Firefox 43 (see bug 1189644.)

Syntax

event.waitUntil(promise)

Returns

None.

Parameters

Promise.

Example

self.addEventListener('push', function(event) {
  console.log('Received a push message', event);

  var title = 'Yay a message.';
  var body = 'We have received a push message.';
  var icon = '/images/icon-192x192.png';
  var tag = 'simple-push-demo-notification-tag';

  event.waitUntil(
    self.registration.showNotification(title, {
      body: body,
      icon: icon,
      tag: tag
    })
  );
});

Specifications

Specification Status Comment
Service Workers
La définition de 'waitUntil()' dans cette spécification.
Version de travail Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 40.0[1] 44.0 (44.0)[2] Pas de support 24 Pas de support
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support Pas de support Pas de support 44.0 (44.0) (Oui) Pas de support ? Pas de support 40.0 [1]

See also

 

Étiquettes et contributeurs liés au document

 Contributeurs à cette page : bendenoz
 Dernière mise à jour par : bendenoz,