e01.org

ServiceWorkerGlobalScope: backgroundfetchclick event

Background Fetch APIservice

Background Fetch APIservice

The **`backgroundfetchclick`** event of the 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](/docs/Web/API/Background_Fetch_API) operation.

This event is not cancelable and does not bubble.

## Syntax

Use the event name in addEventListener():

```js-nolint
addEventListener("backgroundfetchclick", (event) => { })
```

Alternatively, assign to the [event handler property](/docs/Web/API/Document_Object_Model/Events#using_onevent_properties) of the interface:

```js-nolint
onbackgroundfetchclick = (event) => { }
```

## Event type

A BackgroundFetchEvent.

BackgroundFetchEvent

## Description

When a [background fetch](/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 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

## Browser compatibility

## See also

- [Background Fetch API](/docs/Web/API/Background_Fetch_API)

source: MDN Web Docs mirror · page

Cite this

"ServiceWorkerGlobalScope: backgroundfetchclick event". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/backgroundfetchclick_event

JSON record · API collection · citation policy