-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
52 lines (41 loc) · 1.05 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
---
title: "Client: url property"
short-title: url
slug: Web/API/Client/url
page-type: web-api-instance-property
browser-compat: api.Client.url
---
{{APIRef("Service Workers API")}}{{AvailableInWorkers("service")}}
The **`url`** read-only property of the {{domxref("Client")}}
interface returns the URL of the current service worker client.
## Value
A string.
## Examples
```js
self.addEventListener("notificationclick", (event) => {
console.log("On notification click: ", event.notification.tag);
event.notification.close();
// This looks to see if the current is already open and
// focuses if it is
event.waitUntil(
clients
.matchAll({
type: "window",
})
.then((clientList) => {
for (const client of clientList) {
if (client.url === "/" && "focus" in client) {
return client.focus();
}
}
if (clients.openWindow) {
return clients.openWindow("/");
}
}),
);
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}