Skip to content

Commit

Permalink
fix(service-worker): do not register if not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
benji6 committed Jul 6, 2024
1 parent ca5c188 commit 52edaad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions client/src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ const messagingPromise: Promise<Messaging | void> = isSupported().then(
);

export const getRegistrationToken = async (): Promise<string> => {
const serviceWorkerRegistration = await navigator.serviceWorker.ready;
const messaging = await messagingPromise;
if (!messaging)
throw Error("Firebase messaging is not supported in this browser");
return getToken(messaging, {
serviceWorkerRegistration,
serviceWorkerRegistration: await navigator.serviceWorker.ready,
vapidKey: PUBLIC_VAPID_KEY,
});
};
9 changes: 5 additions & 4 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import store from "./store";

export const queryClient = new QueryClient();

navigator.serviceWorker.register(
new URL("service-worker.ts", import.meta.url),
{ type: "module" },
);
if ("serviceWorker" in navigator)
navigator.serviceWorker.register(
new URL("service-worker.ts", import.meta.url),
{ type: "module" },
);

navigator.storage.estimate().then((estimate) => {
if (
Expand Down

0 comments on commit 52edaad

Please sign in to comment.