Service Workers API
当状态为activated 时, ServiceWorkerContainer 接口的只读属性 controller 返回一个 ServiceWorker 对象(与 ServiceWorkerRegistration.active 返回的对象是同一个)。当页面强制刷新 (Shift + refresh) 或不存在 active worder 时,该属性返回 null 。
语法
var myController = navigator.serviceWorker.controller;
值
一个ServiceWorker对象。
示例
if ("serviceWorker" in navigator) {
// Do a one-off check to see if a service worker's in control.
if (navigator.serviceWorker.controller) {
console.log(
"This page is currently controlled by:",
navigator.serviceWorker.controller,
);
} else {
console.log(
"This page is not currently controlled " + "by a service worker.",
);
}
} else {
console.log("Service workers are not supported.");
}
规范
浏览器兼容性
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
