The FetchEvent() constructor creates a new FetchEvent object.
On this page
FetchEvent: FetchEvent() constructor
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
Requestobject that would have triggered the event handler. -
preloadResponse -
A
Promisewhich returns a previously-loaded response to the client. clientIdOptional-
The
Clientthat the current service worker is controlling. It defaults to"". isReloadDeprecated Optional-
A boolean value that signifies whether the page was reloaded or not when the event was dispatched.
trueif yes, andfalseif 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 tofalse. replacesClientIdOptional-
A string which identifies the client which is being replaced by
resultingClientId. It defaults to"". resultingClientIdOptional-
A string containing the new
clientIdif 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 # dom-fetchevent-fetchevent |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
FetchEvent |
44 | 17 | 44 | No | 31 | 11.1 | 44 | 44 | 44 | 32 | 11.3 | 4.0 |
See also
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/FetchEvent