From b7fa70e191625b7de4755bd1e44f3890adf62a62 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Thu, 18 Jul 2024 16:35:07 +0100 Subject: [PATCH] refactor: notification services controller - silently handle push notifications (#4536) ## Explanation Even if extensions permit push notifications, browsers can still block push notifications. This change allows push notifications to silently fail, and allow notifications to still be created. ## References ## Changelog ### `@metamask/notification-services-controller` - **ADDED**: catch statements to log and silently fail push notification actions. ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate --- .../NotificationServicesController.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts index 87573d62a9..f7d6747180 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts @@ -284,28 +284,40 @@ export default class NotificationServicesController extends BaseController< if (!this.#isPushIntegrated) { return; } - await this.messagingSystem.call( - 'NotificationServicesPushController:enablePushNotifications', - UUIDs, - ); + try { + await this.messagingSystem.call( + 'NotificationServicesPushController:enablePushNotifications', + UUIDs, + ); + } catch (e) { + log.error('Silently failed to enable push notifications', e); + } }, disablePushNotifications: async (UUIDs: string[]) => { if (!this.#isPushIntegrated) { return; } - await this.messagingSystem.call( - 'NotificationServicesPushController:disablePushNotifications', - UUIDs, - ); + try { + await this.messagingSystem.call( + 'NotificationServicesPushController:disablePushNotifications', + UUIDs, + ); + } catch (e) { + log.error('Silently failed to disable push notifications', e); + } }, updatePushNotifications: async (UUIDs: string[]) => { if (!this.#isPushIntegrated) { return; } - await this.messagingSystem.call( - 'NotificationServicesPushController:updateTriggerPushNotifications', - UUIDs, - ); + try { + await this.messagingSystem.call( + 'NotificationServicesPushController:updateTriggerPushNotifications', + UUIDs, + ); + } catch (e) { + log.error('Silently failed to update push notifications', e); + } }, subscribe: () => { if (!this.#isPushIntegrated) {