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.
controller
は ServiceWorkerContainer
インターフェイスの読み取り専用プロパティで、ServiceWorker
オブジェクトの状態が activating
または activated
ならそれ (ServiceWorkerRegistration.active
で返されるのと同じオブジェクト) を返します。このプロパティはリクエストが強制リフレッシュ(Shift + リフレッシュ)やアクティブワーカーがない場合は null
を返します。
値
ServiceWorker
オブジェクト。
例
js
if ("serviceWorker" in navigator) {
// 1 回限りのチェックを行って、サービスワーカーが制御しているかどうかを確認します。
if (navigator.serviceWorker.controller) {
console.log(
`このページを現在制御しているもの: ${navigator.serviceWorker.controller}`,
);
} else {
console.log("このページは現在サービスワーカーによって制御されていません。");
}
} else {
console.log("サービスワーカーをサポートしていません。");
}
仕様書
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.