Это экспериментальная технология
Так как спецификация этой технологии ещё не стабилизировалась, смотрите таблицу совместимости по поводу использования в различных браузерах. Также заметьте, что синтаксис и поведение экспериментальной технологии может измениться в будущих версиях браузеров, вслед за изменениями спецификации.

ServiceWorker API предоставляет интерфейс ServiceWorkerContainer, являющийся объектом (объект представляет собой сервис воркер, как единое целое в сетевой экосистеме) включающим следующие средства:
Отмена регистрации;
Обновление сервис воркеров;
Доступ к состоянию сервис воркеров;
Доступ к регистрации сервис воркеров.

Most importantly, it exposes the ServiceWorkerContainer.register(scriptURL, scope[, base]) method used to register service workers, and the ServiceWorkerContainer.controller property used to determine whether or not the current page is actively controlled.


ServiceWorkerContainer.controller Только для чтения
Returns a ServiceWorker object if its state is activated (the same object returned by (en-US)). This property returns null if the request is a force refresh (Shift + refresh) or if there is no active worker.
ServiceWorkerContainer.ready (en-US) Только для чтения
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 (en-US) worker.

Event handlers

ServiceWorkerContainer.oncontrollerchange (en-US)
An event handler fired whenever a controllerchange event occurs — when the document's associated ServiceWorkerRegistration acquires a new (en-US) worker.
ServiceWorkerContainer.onerror (en-US)
An event handler fired whenever an error (en-US) event occurs in the associated service workers.
ServiceWorkerContainer.onmessage (en-US)
An event handler fired whenever a message event occurs — when incoming messages are received to the ServiceWorkerContainer object (e.g. via a MessagePort.postMessage() (en-US) call.)


Creates or updates a ServiceWorkerRegistration for the given scriptURL.
ServiceWorkerContainer.getRegistration() (en-US)
Gets a ServiceWorkerRegistration object whose scope URL matches the provided document URL.  If the method can't return a ServiceWorkerRegistration, it returns a Promise
ServiceWorkerContainer.getRegistrations() (en-US)
Returns all ServiceWorkerRegistrations associated with a ServiceWorkerContainer in an array.  If the method can't return ServiceWorkerRegistrations, it returns a Promise


This code snippet is from the service worker fallback-response sample (see fallback-response live). The code checks to see if the browser supports service workers. Then the code registers the service worker and determines if the page is actively controlled by the service worker. If it isn't, it prompts the user to reload the page so the service worker can take control. The code also reports any registration failures.

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('service-worker.js', {scope: './'}).then(function() {
    if (navigator.serviceWorker.controller) {
      document.querySelector('#status').textContent = 'The service worker is currently handling network operations.';
    } else {
      document.querySelector('#status').textContent = 'Please reload this page to allow the service worker to handle network operations.';
  }).catch(function(error) {
    document.querySelector('#status').textContent = error;
} else {
  var aElement = document.createElement('a');
  aElement.href = '';
  aElement.textContent = 'unavailable';


Specification Status Comment
Service Workers
Определение 'ServiceWorkerContainer' в этой спецификации.
Рабочий черновик Initial definition.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 40.0 44.0 (44.0)[1] Нет 24 Нет
Feature Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? 44.0 (44.0) (Да) Нет ? Нет ?

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

See also