ServiceWorker.state
Posted Tekkaman
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ServiceWorker.state相关的知识,希望对你有一定的参考价值。
【ServiceWorker.state】
ServiceWorker.state
The state
read-only property of the ServiceWorker
interface returns a string representing the current state of the service worker. It can be one of the following values: installing
, installed,
activating
, activated
, or redundant
.
ServiceWorkerRegistration.installing
The installing
property of the ServiceWorkerRegistration
interface returns a service worker whoseServiceWorker.state
is installing
. This property is initially set to null
.
ServiceWorkerRegistration.waiting
The waiting
property of the ServiceWorkerRegistration
interface returns a service worker whoseServiceWorker.state
is installed
. This property is initially set to null
.
ServiceWorkerRegistration.active
The active
property of the ServiceWorkerRegistration
interface returns a service worker whoseServiceWorker.state
is activating
or activated
. This property is initially set to null
.
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); }); }
ServiceWorkerContainer.controller
The controller
read-only property of the ServiceWorkerContainer
interface returns a ServiceWorker
object if its state is activated
(the same object returned by ServiceWorkerRegistration.active
). This property returns null
if the request is a force refresh (Shift + refresh) or if there is no active worker.
参考:
1、https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/state
2、https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/waiting
以上是关于ServiceWorker.state的主要内容,如果未能解决你的问题,请参考以下文章