-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
59 lines (41 loc) · 1.45 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: "ServiceWorkerRegistration: index property"
short-title: index
slug: Web/API/ServiceWorkerRegistration/index
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.ServiceWorkerRegistration.index
---
{{APIRef("Service Workers API")}}{{SeeCompatTable}}{{SecureContext_Header}}{{AvailableInWorkers}}
The **`index`** read-only property of the
{{domxref("ServiceWorkerRegistration")}} interface returns a reference to the
{{domxref('ContentIndex')}} interface, which allows for indexing of offline content.
## Value
A {{domxref('ContentIndex')}} object.
## Examples
You can access the property from either your main script or the registered service
worker.
Here is an example from the main script:
```js
// reference registration
const registration = await navigator.serviceWorker.ready;
// feature detection
if ("index" in registration) {
// Content Index API functionality
const contentIndex = registration.index;
}
```
From the [service worker](/en-US/docs/Web/API/ServiceWorker):
```js
// service worker script
const contentIndex = self.registration.index;
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Content Index API")}}
- [An introductory article on the Content Index API](https://developer.chrome.com/docs/capabilities/web-apis/content-indexing-api)
- [An app which uses the Content Index API to list and remove 'save for later' content](https://contentindex.dev/)