This allows a service worker to get its ServiceWorker object with self.serviceWorker in a service worker script and its current state with self.serviceWorker.state in the script.

Motivation

A service worker instance currently has no way to get its current lifecycle state. There's a bit of a hack one can do where you keep track of the current event as a global variable but that's error prone and doesn't capture the waiting periods correctly. The best way to solve this would be to just allow a service worker to get its ServiceWorker object in a service worker script.

Demo

Documentation

Specification

Editor's draft

Status in Chromium

Blink>ServiceWorker


Enabled by default (tracking bug) in:

  • Chrome for desktop release 79
  • Chrome for Android release 79
  • Android WebView release 79

Consensus & Standardization

After a feature ships in Chrome, the values listed here are not guaranteed to be up to date.

Owners

Intent to Prototype url

Intent to Prototype thread

Search tags

Service Worker,

Last updated on 2020-11-09