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.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

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 GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
serviceWorker

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

参见