FetchEvent Class

The fetch event of a service worker (https://w3c.github.io/ServiceWorker/#fetchevent): a request of a client of the service worker, which the service worker can answer with FetchEvent.RespondWith. The request and the response are Request and Response objects of the script engine (the Fetch API is implemented in JavaScript).

public sealed class FetchEvent : ExtendableEvent
Inheritance
ExtendableEvent FetchEvent

Constructors

NameDescription
FetchEvent(string, FetchEventInit)Creates a fetch event.

FetchEvent(string, FetchEventInit)

ExtendableEvents.cs

Creates a fetch event.

public FetchEvent(string type, FetchEventInit eventInitDict)

Properties

NameDescription
ClientIdGets the id of the client of the request, or an empty string.
HandledGets the promise fulfilled once the event was handled.
PreloadResponseGets the promise of the response of the navigation preload (a Response object of the script engine, or undefined).
ReplacesClientIdGets the id of the client replaced by a navigation, or an empty string.
RequestGets the request: a Request object of the script engine.
ResultingClientIdGets the id of the client created by a navigation, or an empty string.

Gets the id of the client of the request, or an empty string.

public string ClientId { get; }

Gets the promise fulfilled once the event was handled.

public Task Handled { get; }

PreloadResponse

ExtendableEvents.cs

Gets the promise of the response of the navigation preload (a Response object of the script engine, or undefined).

public Task<object?> PreloadResponse { get; }

ReplacesClientId

ExtendableEvents.cs

Gets the id of the client replaced by a navigation, or an empty string.

public string ReplacesClientId { get; }

Gets the request: a Request object of the script engine.

public object Request { get; }

ResultingClientId

ExtendableEvents.cs

Gets the id of the client created by a navigation, or an empty string.

public string ResultingClientId { get; }

Methods

NameDescription
RespondWith(Task<object?>)Answers the request with a response (https://w3c.github.io/ServiceWorker/#dom-fetchevent-respondwith): the promise must be fulfilled with a Response object, else the request is a network error.

RespondWith(Task<object?>)

ExtendableEvents.cs

Answers the request with a response (https://w3c.github.io/ServiceWorker/#dom-fetchevent-respondwith): the promise must be fulfilled with a Response object, else the request is a network error.

public void RespondWith(Task<object?> r)

Parameters

r Task<object?>

Exceptions

DomException
An InvalidStateError when the event is not being dispatched, or when the method was already called.

See also