From 34a6144c3aea360a52ab8c819b9743d39c8188e8 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 11 Aug 2021 11:16:03 +0200 Subject: [PATCH] =?UTF-8?q?Handle=20service=20worker=20registration=20with?= =?UTF-8?q?=20Firefox=20=C2=AB=C2=A0forget=20all=20site=20data=C2=A0=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the Firefox setting « Delete cookies and site data when Firefox is closed », we can't register the service worker and then webpush notification can't work Closes #819 Signed-off-by: Thomas Citharel --- js/src/views/Settings/Notifications.vue | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/js/src/views/Settings/Notifications.vue b/js/src/views/Settings/Notifications.vue index 8a4962fee..805e8bc85 100644 --- a/js/src/views/Settings/Notifications.vue +++ b/js/src/views/Settings/Notifications.vue @@ -686,10 +686,15 @@ export default class Notifications extends Vue { } async checkCanShowWebPush(): Promise { - if (!window.isSecureContext || !("serviceWorker" in navigator)) + try { + if (!window.isSecureContext || !("serviceWorker" in navigator)) + return Promise.resolve(false); + const registration = await navigator.serviceWorker.getRegistration(); + return registration !== undefined; + } catch (e) { + console.error(e); return Promise.resolve(false); - const registration = await navigator.serviceWorker.getRegistration(); - return registration !== undefined; + } } async created(): Promise { @@ -713,9 +718,14 @@ export default class Notifications extends Vue { } private async isSubscribed(): Promise { - if (!("serviceWorker" in navigator)) return Promise.resolve(false); - const registration = await navigator.serviceWorker.getRegistration(); - return (await registration?.pushManager?.getSubscription()) != null; + try { + if (!("serviceWorker" in navigator)) return Promise.resolve(false); + const registration = await navigator.serviceWorker.getRegistration(); + return (await registration?.pushManager?.getSubscription()) != null; + } catch (e) { + console.error(e); + return Promise.resolve(false); + } } private async deleteFeedToken(token: string): Promise {