diff --git a/.changeset/cuddly-bears-return.md b/.changeset/cuddly-bears-return.md new file mode 100644 index 00000000..1283b900 --- /dev/null +++ b/.changeset/cuddly-bears-return.md @@ -0,0 +1,5 @@ +--- +'@capacitor-firebase/messaging': patch +--- + +fix(web): check if notifications are supported before checking or requesting permission diff --git a/packages/messaging/src/web.ts b/packages/messaging/src/web.ts index 754f1f70..8e7fcb5a 100644 --- a/packages/messaging/src/web.ts +++ b/packages/messaging/src/web.ts @@ -44,6 +44,12 @@ export class FirebaseMessagingWeb } public async checkPermissions(): Promise { + const isSupported = await isSupportedInWeb(); + if (!isSupported) { + return { + receive: 'denied', + }; + } const receive = this.convertNotificationPermissionToPermissionState( Notification.permission, ); @@ -53,6 +59,12 @@ export class FirebaseMessagingWeb } public async requestPermissions(): Promise { + const isSupported = await isSupportedInWeb(); + if (!isSupported) { + return { + receive: 'denied', + }; + } const notificationPermission = await Notification.requestPermission(); const receive = this.convertNotificationPermissionToPermissionState( notificationPermission,