ServiceWorkerRegistration: index 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

注意:此功能在 Web Workers 中可用。

ServiceWorkerRegistration 接口中只读的 index 属性返回一个指向 ContentIndex 接口的引用,该接口允许索引离线内容。

一个 ContentIndex 对象。

示例

您可以从主脚本或已注册的服务工作者访问该属性。

这是主脚本中的一个示例

js
// reference registration
const registration = await navigator.serviceWorker.ready;

// feature detection
if ("index" in registration) {
  // Content Index API functionality
  const contentIndex = registration.index;
}

来自 服务工作者

js
// service worker script

const contentIndex = self.registration.index;

规范

规范
Content Index
# dom-serviceworkerregistration-index

浏览器兼容性

另见