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

瀏覽器相容性

另見