Service Worker Sample: Immediate Control

Available in Chrome 42+

This sample is a modified version of the detailed registration sample. It shows off two new methods available to service workers:

While both of those methods have independent uses, when used together they ensure that when there's an update to the underlying service worker, the update takes effect immediately and applies to both the current page and all other active pages. It's important that your new service worker code behaves properly when assuming control of a page that might have been initially loaded with an older version of your service worker and older cache entries. If you're not sure that it will, then relying on the default service lifecycle behavior may be more appropriate.

Various pieces of information about the service worker from the perspective of the registering page can be found below. Additionally, visit chrome://inspect/#service-workers and click on the "inspect" link below the registered service worker to view logging statements for the various actions the service-worker.js script is performing.

Service Worker Availability

Service Workers available in your browser. (Whether 'serviceWorker' in navigator.)

Is This Page Controlled by a Service Worker?

This page currently controlled. (Whether navigator.serviceWorker.controller is set.)

Info about the Current Registration

The navigator.serviceWorker.register() call .

The current registration represents the service worker.

Tip: With a newly registered service worker in the activated state, refresh the page to have the service worker take control. You can also refresh with the Shift key held down to load the page without the service worker controlling it.

State transitions of the service worker associated with the current registration: