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: installinginstalled, activatingactivated, 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);
  });
}
View Code

 

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的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数