FetchEvent: FetchEvent() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

Note: This feature is only available in Service Workers.

The FetchEvent() constructor creates a new FetchEvent object.

Syntax

js
new FetchEvent(type, options)

Parameters

type

A string with the name of the event. It is case-sensitive and browsers always set it to fetch.

options

An object that, in addition of the properties defined in ExtendableEvent(), can have the following properties:

request

The Request object that would have triggered the event handler.

preloadResponse

A Promise which returns a previously-loaded response to the client.

clientId Optional

The Client that the current service worker is controlling. It defaults to "".

isReload Optional

A boolean value that signifies whether the page was reloaded or not when the event was dispatched. true if yes, and false if not. Typically, pressing the refresh button in a browser is a reload, while clicking a link and pressing the back button is not. If not present, it defaults to false.

replacesClientId Optional

A string which identifies the client which is being replaced by resultingClientId. It defaults to "".

resultingClientId Optional

A string containing the new clientId if the client changes as a result of the page load. It defaults to ""

handled

A pending promise that will be fulfilled once the event has been handled.

Return value

A new FetchEvent object.

Specifications

Specification
Service Workers Nightly
# dom-fetchevent-fetchevent

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
FetchEvent() constructor
Chrome – Full support
Chrome 44 (Release date: 2015-07-21)
footnote Full support
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 31 (Release date: 2015-08-04)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 44 (Release date: 2015-07-29)
footnote Full support
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 32 (Release date: 2015-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – Full support
WebView Android 44 (Release date: 2015-07-29)
footnote Full 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

See also