-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
51 lines (37 loc) · 1.37 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
---
title: "ServiceWorkerContainer: getRegistration() method"
short-title: getRegistration()
slug: Web/API/ServiceWorkerContainer/getRegistration
page-type: web-api-instance-method
browser-compat: api.ServiceWorkerContainer.getRegistration
---
{{APIRef("Service Workers API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The **`getRegistration()`** method of the
{{domxref("ServiceWorkerContainer")}} interface gets a
{{domxref("ServiceWorkerRegistration")}} object whose scope URL matches the provided
client URL. The method returns a {{jsxref("Promise")}} that resolves to
a {{domxref("ServiceWorkerRegistration")}} or `undefined`.
## Syntax
```js-nolint
getRegistration()
getRegistration(clientURL)
```
### Parameters
- `clientURL` {{optional_inline}}
- : The registration whose scope matches this URL will be returned. Relative URLs are resolved with the current client as the base. If this parameter is not provided, the current client's URL will be used by default.
### Return value
A {{jsxref("Promise")}} that resolves to a {{domxref("ServiceWorkerRegistration")}}
object or `undefined`.
## Examples
```js
navigator.serviceWorker.getRegistration("/app").then((registration) => {
if (registration) {
document.querySelector("#status").textContent =
"ServiceWorkerRegistration found.";
}
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}