Skip to content

Commit

Permalink
fix(messaging): check if notifications are supported before checking …
Browse files Browse the repository at this point in the history
…or requesting permission (#701)
  • Loading branch information
robingenz authored Dec 16, 2024
1 parent 6bb49b5 commit cabf5ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-bears-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/messaging': patch
---

fix(web): check if notifications are supported before checking or requesting permission
12 changes: 12 additions & 0 deletions packages/messaging/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export class FirebaseMessagingWeb
}

public async checkPermissions(): Promise<PermissionStatus> {
const isSupported = await isSupportedInWeb();
if (!isSupported) {
return {
receive: 'denied',
};
}
const receive = this.convertNotificationPermissionToPermissionState(
Notification.permission,
);
Expand All @@ -53,6 +59,12 @@ export class FirebaseMessagingWeb
}

public async requestPermissions(): Promise<PermissionStatus> {
const isSupported = await isSupportedInWeb();
if (!isSupported) {
return {
receive: 'denied',
};
}
const notificationPermission = await Notification.requestPermission();
const receive = this.convertNotificationPermissionToPermissionState(
notificationPermission,
Expand Down

0 comments on commit cabf5ac

Please sign in to comment.