Navigator:serviceWorker 属性
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.
Navigator
接口的 serviceWorker
只读属性返回关联文档的 ServiceWorkerContainer
对象,用于提供 ServiceWorker
的注册、移除、升级和通信的访问。
该特性可能无法在无痕模式下使用。
请注意,worker 同样可以通过 WorkerNavigator.serviceWorker
访问文档的 ServiceWorkerContainer
。
值
示例
此代码检查浏览器是否支持 service worker。
js
if ("serviceWorker" in navigator) {
// 支持!
}
规范
Specification |
---|
Service Workers # navigator-service-worker-attribute |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
serviceWorker |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
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.