From 7a14d56f9f3a333139fd9f91bac5e0a9a8f2a4d0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 5 Jan 2023 11:57:44 -0600 Subject: [PATCH] ServiceWorker: drop empty push events --- app/soapbox/service-worker/web-push-notifications.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/soapbox/service-worker/web-push-notifications.ts b/app/soapbox/service-worker/web-push-notifications.ts index 5763977e0..be40aa183 100644 --- a/app/soapbox/service-worker/web-push-notifications.ts +++ b/app/soapbox/service-worker/web-push-notifications.ts @@ -134,7 +134,10 @@ const htmlToPlainText = (html: string): string => /** ServiceWorker `push` event callback. */ const handlePush = (event: PushEvent) => { - const { access_token, notification_id, preferred_locale, title, body, icon } = event.data?.json(); + // If event has no data, stop here. + if (!event.data) return; + + const { access_token, notification_id, preferred_locale, title, body, icon } = event.data.json(); // Placeholder until more information can be loaded event.waitUntil(