SwRuntimeManager
Exposes installing, registration, waiting and updateAvailable state and manages service worker updates.
Table of contents
Category
Value
Import
jsimport { SwRuntimeManager } from "valyrian.js/sw";Public signature
tsnew SwRuntimeManager(options?: CreateSwRuntimeOptions): SwRuntimeManagerAPI form
SwRuntimeManager is a class. Construct it in the browser, subscribe to the states needed by the interface and call init() to register the configured worker.
Options and defaults
tstype CreateSwRuntimeOptions = {
swUrl?: string; // "./sw.js"
scope?: string; // "/"
strategy?: "prompt-user" | "auto" | "manual"; // "prompt-user"
runtime?: {
isNodeJs?: boolean;
navigator?: Navigator | null;
window?: Window | null;
};
};State and methods
tsreadonly state: {
updateAvailable: boolean;
installing: boolean;
registration: ServiceWorkerRegistration | null;
waiting: ServiceWorker | null;
}
init(): Promise<this>
applyUpdate(): void
checkForUpdate(): Promise<void>
unregister(): Promise<boolean>
on("registered" | "updateavailable" | "updated" | "error", callback): () => void
off(event, callback): voidStrategies and events
prompt-user waits for the application to call applyUpdate(). auto applies a waiting worker automatically. manual avoids automatic application and reload. controllerchange emits updated and reloads unless the strategy is manual. Registration failures emit error.