// Background Fetch
// Specification: https://wicg.github.io/background-fetch/
// Repository: https://github.com/WICG/background-fetch/
///
///
interface ServiceWorkerGlobalScope {
onbackgroundfetchsuccess: ((this: ServiceWorkerGlobalScope, ev: BackgroundFetchEvent) => any) | null;
onbackgroundfetchfail: ((this: ServiceWorkerGlobalScope, ev: BackgroundFetchEvent) => any) | null;
onbackgroundfetchabort: ((this: ServiceWorkerGlobalScope, ev: BackgroundFetchEvent) => any) | null;
onbackgroundfetchclick: ((this: ServiceWorkerGlobalScope, ev: BackgroundFetchEvent) => any) | null;
}
interface ServiceWorkerGlobalScopeEventMap {
"backgroundfetchsuccess": BackgroundFetchEvent;
"backgroundfetchfail": BackgroundFetchEvent;
"backgroundfetchabort": BackgroundFetchEvent;
"backgroundfetchclick": BackgroundFetchEvent;
}
interface ServiceWorkerRegistration {
readonly backgroundFetch: BackgroundFetchManager;
}
interface BackgroundFetchManager {
fetch(id: string, requests: RequestInfo | RequestInfo[], options?: BackgroundFetchOptions): Promise;
get(id: string): Promise;
getIds(): Promise;
}
interface BackgroundFetchUIOptions {
icons?: ImageResource[];
title?: string;
}
interface BackgroundFetchOptions extends BackgroundFetchUIOptions {
downloadTotal?: number;
}
declare class BackgroundFetchRegistration extends EventTarget {
readonly id: string;
readonly uploadTotal: number;
readonly uploaded: number;
readonly downloadTotal: number;
readonly downloaded: number;
readonly result: BackgroundFetchResult;
readonly failureReason: BackgroundFetchFailureReason;
readonly recordsAvailable: boolean;
onprogress: ((this: ServiceWorkerGlobalScope, ev: BackgroundFetchEvent) => any) | null;
addEventListener(type: K, listener: (this: BackgroundFetchRegistration, ev: BackgroundFetchRegistrationEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener(type: K, listener: (this: BackgroundFetchRegistration, ev: BackgroundFetchRegistrationEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
abort(): Promise;
match(request: RequestInfo, options?: CacheQueryOptions): Promise;
matchAll(request?: RequestInfo, options?: CacheQueryOptions): Promise;
}
interface BackgroundFetchRegistrationEventMap {
"progress": BackgroundFetchEvent;
}
type BackgroundFetchResult = (
| ""
| "success"
| "failure"
);
type BackgroundFetchFailureReason = (
| ""
| "aborted"
| "bad-status"
| "fetch-error"
| "quota-exceeded"
| "download-total-exceeded"
);
declare class BackgroundFetchRecord {
readonly request: Request;
readonly responseReady: Promise;
}
declare class BackgroundFetchEvent extends ExtendableEvent {
constructor(type: string, init: BackgroundFetchEventInit);
readonly registration: BackgroundFetchRegistration;
}
interface BackgroundFetchEventInit extends ExtendableEventInit {
registration: BackgroundFetchRegistration;
}
declare class BackgroundFetchUpdateUIEvent extends BackgroundFetchEvent {
constructor(type: string, init: BackgroundFetchEventInit);
updateUI(options?: BackgroundFetchUIOptions): Promise;
}