-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
74 lines (47 loc) · 2.48 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
title: "ServiceWorkerGlobalScope: backgroundfetchclick event"
short-title: backgroundfetchclick
slug: Web/API/ServiceWorkerGlobalScope/backgroundfetchclick_event
page-type: web-api-event
status:
- experimental
browser-compat: api.ServiceWorkerGlobalScope.backgroundfetchclick_event
---
{{APIRef("Background Fetch API")}}{{SeeCompatTable}}{{SecureContext_Header}}{{AvailableInWorkers("service")}}
The **`backgroundfetchclick`** event of the {{domxref("ServiceWorkerGlobalScope")}} interface is fired when the user clicks on the UI that the browser provides to show the user the progress of the [background fetch](/en-US/docs/Web/API/Background_Fetch_API) operation.
This event is not cancelable and does not bubble.
## Syntax
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
```js
addEventListener("backgroundfetchclick", (event) => {});
onbackgroundfetchclick = (event) => {};
```
## Event type
A {{domxref("BackgroundFetchEvent")}}.
{{InheritanceDiagram("BackgroundFetchEvent")}}
## Event properties
_Inherits properties from its parent, {{domxref("ExtendableEvent")}}._
- {{domxref("BackgroundFetchEvent.registration")}}
- : Returns the {{domxref("BackgroundFetchRegistration")}} whose progress dialog the user clicked on.
## Description
When a [background fetch](/en-US/docs/Web/API/Background_Fetch_API) operation starts, the browser shows a UI element to the user to indicate the progress of the operation. If the user clicks this element, the browser starts the service worker, if necessary, and fires the `backgroundfetchclick` event in the service worker's global scope.
A common task for the handler in this situation is to open a window giving the user more details about the fetch operation.
## Examples
### Opening a window with more details
This event handler uses the global {{domxref("ServiceWorkerGlobalScope.clients", "clients")}} property to open a window giving the user more details about the fetch. It opens a different window depending on whether the fetch has completed or not.
```js
addEventListener("backgroundfetchclick", (event) => {
const registration = event.registration;
if (registration.result === "success") {
clients.openWindow("/play-movie");
} else {
clients.openWindow("/movie-download-progress");
}
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [Background Fetch API](/en-US/docs/Web/API/Background_Fetch_API)