/** * How long, by default, the page waits for its ServiceWorker to activate and * to take control before giving up. Generous: a first install downloads and * evaluates the worker script, which on a slow link takes seconds. */ export declare const DEFAULT_SERVICE_WORKER_TIMEOUT = 30000; /** Channel call a page sends to ask its ServiceWorker to `clients.claim()` it. */ export declare const CLAIM_CALL = "CLAIM"; /** * - `activation-timeout`: the worker did not activate in time. * - `uncontrolled`: the worker is active but the page is not controlled by it. * - `unresponsive`: the page is controlled, but the worker did not answer the * adapter's handshake in time. * - `incompatible`: the worker answered, but runs another version of this * package's link protocol. */ export type ServiceWorkerControlFailure = "activation-timeout" | "uncontrolled" | "unresponsive" | "incompatible"; /** * Why a page could not get a working ServiceWorker. `reason` says which wait * failed; check it (or `name`) rather than `instanceof`, because each of this * package's bundles carries its own copy of this class. */ export declare class ServiceWorkerControlError extends Error { readonly reason: ServiceWorkerControlFailure; constructor(reason: ServiceWorkerControlFailure, message: string); } export interface AwaitServiceWorkerOptions { /** Upper bound for the whole wait, in ms. Default `DEFAULT_SERVICE_WORKER_TIMEOUT`. */ timeout?: number; } export interface AwaitServiceWorkerControlOptions extends AwaitServiceWorkerOptions { /** * When the page is still uncontrolled after asking the worker to claim it, * reload the page once instead of rejecting. A normal reload is a * navigation, and navigations are controlled. Guarded by `sessionStorage` * so it never loops: if the reloaded page is uncontrolled too, it rejects. * Default `false`. */ reloadIfUncontrolled?: boolean; /** For tests. Default `navigator.serviceWorker`. */ container?: ServiceWorkerContainer; } /** * Resolves with the registration's worker once it is `activated`. Rejects * with a `ServiceWorkerControlError` (`reason: "activation-timeout"`) if that * takes longer than `timeout` — an install that throws or never finishes * would otherwise leave the caller waiting forever. */ export declare function awaitActiveServiceWorker(registration: ServiceWorkerRegistration, { timeout }?: AwaitServiceWorkerOptions): Promise; /** * Resolves with the ServiceWorker that controls this page, once `registration` * has an activated worker and the page is controlled by it. * * A page can stay uncontrolled while its worker is active, and then no * `controllerchange` ever fires on its own: * - a hard reload (Ctrl+Shift+R) bypasses the worker for that load, and the * worker's `clients.claim()` already ran when it activated; * - Firefox can leave a page loaded while the worker is running uncontrolled. * * So when the page is uncontrolled, this asks the active worker to claim it * again (a `CLAIM` channel call — this package's workers answer it) and waits * for `controllerchange`. Every wait is bounded by `timeout`. If control never * comes it reloads once (`reloadIfUncontrolled`) or rejects with a * `ServiceWorkerControlError` (`reason: "uncontrolled"`) that says what * happened and what to do. */ export declare function awaitServiceWorkerControl(registration: ServiceWorkerRegistration, { timeout, reloadIfUncontrolled, container, }?: AwaitServiceWorkerControlOptions): Promise; /** * ServiceWorker side: answers the page's `CLAIM` request with * `clients.claim()`, which takes over every uncontrolled client in scope. * Returns a function that stops answering. */ export declare function handleClaimRequests(self: ServiceWorkerGlobalScope): () => void; //# sourceMappingURL=service-worker-control.d.ts.map