Experimental: Esta é uma tecnologia experimental (en-US)
Verifique a tabela de compatibilidade entre Navegadores cuidadosamente antes de usar essa funcionalidade em produção.

ServiceWorkerContainer é a interface de ServiceWorker API provides an object representing the service worker as an overall unit in the network ecosystem, including facilities to register, unregister and update service workers, and access the state of service workers and their registrations.

Most importantly, it exposes the ServiceWorkerContainer.register() method used to register service workers, and the ServiceWorkerContainer.controller (en-US) property used to determine whether or not the current page is actively controlled.


ServiceWorkerContainer.controller (en-US) Somente leitura
Returns a ServiceWorker (en-US) object if its state is activated (the same object returned by (en-US)). This property returns null during a force-refresh request (Shift + refresh) or if there is no active worker.
ServiceWorkerContainer.ready (en-US) Somente leitura
Provides a way of delaying code execution until a service worker is active. It returns a Promise that will never reject, and which waits indefinitely until the ServiceWorkerRegistration (en-US) associated with the current page has an (en-US) worker. Once that condition is met, it resolves with the ServiceWorkerRegistration (en-US).

Event handlers

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


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


The example below first checks to see if the browser supports service workers. If supported, 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) {
  // Register a service worker hosted at the root of the
  // site using the default scope.
  navigator.serviceWorker.register('/sw.js').then(function(registration) {
    console.log('Service worker registration succeeded:', registration);

    // At this point, you can optionally do something
    // with registration. See
  }).catch(function(error) {
    console.log('Service worker registration failed:', error);

  // Independent of the registration, let's also display
  // information about whether the current page is controlled
  // by an existing service worker, and when that
  // controller changes.

  // First, do a one-off check if there's currently a
  // service worker in control.
  if (navigator.serviceWorker.controller) {
    console.log('This page is currently controlled by:', navigator.serviceWorker.controller);

  // Then, register a handler to detect when a new or
  // updated service worker takes control.
  navigation.serviceWorker.oncontrollerchange = function() {
    console.log('This page is now controlled by:', navigator.serviceWorker.controller);
} else {
  console.log('Service workers are not supported.');


Specification Status Comment
Service Workers
The definition of 'ServiceWorkerContainer' in that specification.
Rascunho atual Initial definition.

Compatibilidade com navegadores

Estamos convertendo nossos dados de compatibilidade para o formato JSON. Esta tabela de compatibilidade ainda usa o formato antigo, pois ainda não convertemos os dados que ela contém. Descubra como você pode ajudar! (en-US)
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 40 44.0 (44.0)[1] Não suportado 27 Não suportado
Feature Android Webview Chrome for Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support 40 40 44.0 (44.0) (Yes) Não suportado 27 Não suportado

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

See also