feat: offline content

This commit is contained in:
gosangam
2026-07-02 21:32:22 +05:30
parent 0b67a1142f
commit 380c23e469
13 changed files with 969 additions and 14 deletions
+8 -5
View File
@@ -110,11 +110,14 @@ export async function enablePush(): Promise<void> {
throw new Error("Notification permission was not granted.");
}
// The BFF origin rides along as a query param so the service worker can
// re-register rotated subscriptions (pushsubscriptionchange) on its own.
const reg = await navigator.serviceWorker.register(
`/sw.js?bff=${encodeURIComponent(BFF_BASE)}`,
);
// The service worker is registered app-wide by ServiceWorkerRegistrar (with
// the same `?bff=` query, so there's a single registration/scope). Reuse it;
// only register here as a fallback if it somehow isn't present yet.
const reg =
(await navigator.serviceWorker.getRegistration()) ??
(await navigator.serviceWorker.register(
`/sw.js?bff=${encodeURIComponent(BFF_BASE)}`,
));
await navigator.serviceWorker.ready;
let sub = await reg.pushManager.getSubscription();