// The app's worker, as SKILL.md shows it. Lifecycle is the app's: // nothing here calls skipWaiting or clients.claim either, because this // example has nothing to claim. importScripts("/static/aviso/aviso-sw.js"); const post = (body) => fetch("/aviso/subscribe", { method: "POST", credentials: "same-origin", mode: "same-origin", redirect: "error", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); self.addEventListener("push", (e) => e.waitUntil(AvisoSW.handlePush(e, { fallback: () => ({ title: "aviso example", options: { body: "Something happened.", data: { url: "/" } } }), }))); self.addEventListener("notificationclick", (e) => e.waitUntil(AvisoSW.handleClick(e, { fallbackURL: "/" }))); self.addEventListener("pushsubscriptionchange", (e) => e.waitUntil(AvisoSW.handleSubscriptionChange(e, { // Fetched on demand: a terminated worker forgets its variables. publicKey: () => fetch("/aviso/public-key").then((r) => r.json()).then((j) => j.publicKey), save: post, })));