From 18a151c8e8f3c0b3d14e75b98363852e3b776da6 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 31 Aug 2018 11:17:57 +0200 Subject: [PATCH] Fix Safari Profile page (#1619) --- src/components/ha-push-notifications-toggle.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/ha-push-notifications-toggle.js b/src/components/ha-push-notifications-toggle.js index 39d6d0ef71..a1d72b8503 100644 --- a/src/components/ha-push-notifications-toggle.js +++ b/src/components/ha-push-notifications-toggle.js @@ -45,10 +45,13 @@ class HaPushNotificationsToggle extends EventsMixin(PolymerElement) { async connectedCallback() { super.connectedCallback(); - if (!('serviceWorker' in navigator)) return; + if (!pushSupported) return; try { const reg = await navigator.serviceWorker.ready; + if (!reg.pushManager) { + return; + } reg.pushManager.getSubscription().then((subscription) => { this.loading = false; this.pushChecked = !!subscription; @@ -59,6 +62,10 @@ class HaPushNotificationsToggle extends EventsMixin(PolymerElement) { } handlePushChange(pushChecked) { + // Somehow this is triggered on Safari on page load causing + // it to get into a loop and crash the page. + if (!pushSupported) return; + if (pushChecked) { this.subscribePushNotifications(); } else {