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 的注册、删除、更新以及通信的访问。

该功能可能无法在无痕模式下使用。

示例

此代码检查浏览器是否支持 service worker。

js
if ("serviceWorker" in navigator) {
  // Supported!
}

规范

Specification
Service Workers
# navigator-service-worker-attribute

浏览器兼容性

BCD tables only load in the browser

参见