From 122fd018d0221626bca7889e23da54d5a414e3ba Mon Sep 17 00:00:00 2001 From: or-else Date: Fri, 30 Jul 2021 09:37:25 -0700 Subject: [PATCH] fixing #80 in service-worker --- service-worker.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/service-worker.js b/service-worker.js index 28c21e37..c03dd725 100644 --- a/service-worker.js +++ b/service-worker.js @@ -4,8 +4,9 @@ importScripts('https://cdn.jsdelivr.net/npm/firebase@8.7.1/firebase-messaging.js importScripts('firebase-init.js'); importScripts('version.js'); -// Channel to notify the webapp. -const webAppChannel = new BroadcastChannel('tinode-sw'); +// Channel to notify the webapp. There is no BroadcastChannel in Safari. +const webAppChannel = (typeof BroadcastChannel == 'function') ? + new BroadcastChannel('tinode-sw') : null; // Basic internationalization. const i18n = { @@ -56,7 +57,9 @@ fbMessaging.onBackgroundMessage((payload) => { } // Notify webapp that a message was received. - webAppChannel.postMessage(payload.data); + if (webAppChannel) { + webAppChannel.postMessage(payload.data); + } const pushType = payload.data.what || 'msg'; const title = payload.data.title || self.i18nMessage(pushType == 'msg' ? 'new_message' : 'new_chat');