feat: offline content
This commit is contained in:
+8
-5
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user