From ab63cbb9f765dd754366f4c6fbbf058e1531ed1a Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 11 Jul 2024 16:15:34 +0530 Subject: [PATCH] Fixed: issue when Notification api is not available on browser --- src/utils/firebase.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/firebase.ts b/src/utils/firebase.ts index 7ca8626a..02017a93 100644 --- a/src/utils/firebase.ts +++ b/src/utils/firebase.ts @@ -1,5 +1,5 @@ import { initializeApp } from "firebase/app"; -import { getMessaging, getToken, onMessage } from "firebase/messaging"; +import { getMessaging, getToken, onMessage, isSupported } from "firebase/messaging"; const initialiseFirebaseApp = async ( appFirebaseConfig: any, @@ -9,6 +9,11 @@ const initialiseFirebaseApp = async ( ) => { const firebaseConfig = appFirebaseConfig + if(!await isSupported()) { + console.error("Notifications not supported"); + return; + } + const app = initializeApp(firebaseConfig); const messaging = getMessaging(app); const permission = await Notification.requestPermission();