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

ServiceWorkerContainer.ready

This article needs a technical review. How you can help.

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The ready read-only property of the ServiceWorkerContainer interface defines whether a service worker is ready to control a page or not. It returns a Promise that will never reject, which resolves to a ServiceWorkerRegistration with an ServiceWorkerRegistration.active worker.

Syntax

navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { ... });

Example

function subscribe() {
  var subscribeButton = document.querySelector('.js-subscribe-button');
  subscribeButton.disabled = false;

  navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
    serviceWorkerRegistration.pushManager.subscribe()
      .then(function(subscription) {
        // The subscription was successful
        subscribeButton.disabled = true;
        return sendSubscriptionToServer(subscription);
      })
      .catch(function(error) {
        if (Notification.permission === 'denied') {
          console.log('Permission for Notifications was denied');
          subscribeButton.disabled = true;
        } else {
          console.log('Unable to subscribe to push.', error);
          subscribeButton.disabled = false;
        }
      });
  });
}

Specifications

 
Specification Status Comment
Service Workers
The definition of 'ServiceWorkerRegistration.ready' in that specification.
Working Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 38.0 44.0 (44.0)[1] No support 24 No support
Feature Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? 44.0 (44.0) (Yes) No support ? No support 38.0

[1] Service workers (and Push) have been disabled in the Firefox 45 Extended Support Release (ESR.)

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, kscarfone, jpmedley
 Last updated by: chrisdavidmills,