[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/API/ServiceWorker [Back]  [Original]

ServiceWorker - API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

ServiceWorker

Baseline
Widely available
*

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2018 ..

* Some parts of this feature may have varying levels of support.

ServiceWorker, ServiceWorker API, Service Worker. Service Worker ( , Web Workers, ..), ServiceWorker.

ServiceWorker ServiceWorkerRegistration.active ServiceWorkerContainer.controller Service Worker, ( , Service Worker )

ServiceWorker : install activate , fetch. ServiceWorker ServiceWorker.state, .

In this article

ServiceWorker Worker.

ServiceWorker.scriptURL

URL Service Worker. URL , , ServiceWorker.

ServiceWorker.state

Service Worker. : installing, installed, activating, activated redundant.

ServiceWorker.onstatechange

statechange; , ServiceWorker.state.

ServiceWorker Worker, Worker.terminate, Service Worker.

Service Worker (). ServiceWorker.state .

js
if ("serviceWorker" in navigator) {
  navigator.serviceWorker
    .register("service-worker.js", {
      scope: "./",
    })
    .then(function (registration) {
      var serviceWorker;
      if (registration.installing) {
        serviceWorker = registration.installing;
        document.querySelector("#kind").textContent = "installing";
      } else if (registration.waiting) {
        serviceWorker = registration.waiting;
        document.querySelector("#kind").textContent = "waiting";
      } else if (registration.active) {
        serviceWorker = registration.active;
        document.querySelector("#kind").textContent = "active";
      }
      if (serviceWorker) {
        // logState(serviceWorker.state);
        serviceWorker.addEventListener("statechange", function (e) {
          // logState(e.target.state);
        });
      }
    })
    .catch(function (error) {
      //     Service Worker.
      //  service-worker.js       .
    });
} else {
  //     Service Worker.
}

Specification
Service Workers Nightly
# serviceworker-interface


Web Proxy Viewer  |  New URL  |  Original Page