ServiceWorkerGlobalScope: backgroundfetchclick event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is only available in Service Workers.

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 operation.

This event is not cancelable and does not bubble.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

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

onbackgroundfetchclick = (event) => { }

Event type

A BackgroundFetchEvent.

Event ExtendableEvent BackgroundFetchEvent

Event properties

Inherits properties from its parent, ExtendableEvent.

BackgroundFetchEvent.registration

Returns the BackgroundFetchRegistration whose progress dialog the user clicked on.

Description

When a background fetch 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

Specification
Background Fetch
# dom-serviceworkerglobalscope-onbackgroundfetchclick

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
backgroundfetchclick event
Experimental
Chrome – Full support
Chrome 74 (Release date: 2019-04-23)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 62 (Release date: 2019-06-27)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 74 (Release date: 2019-04-24)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 53 (Release date: 2019-07-11)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

See also