ServiceWorkerContainer.controller
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
当状态为activated
时, ServiceWorkerContainer
接口的只读属性 controller
返回一个 ServiceWorker
对象(与 ServiceWorkerRegistration.active
返回的对象是同一个)。当页面强制刷新 (Shift + refresh) 或不存在 active worder 时,该属性返回 null
。
语法
var myController = navigator.serviceWorker.controller;
值
一个ServiceWorker
对象。
示例
js
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.");
}
规范
Specification |
---|
Service Workers # navigator-service-worker-controller |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
controller |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.