Handle service worker registration with Firefox « forget all site data »

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 <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-08-11 11:16:03 +02:00
parent 5c90fa9659
commit 34a6144c3a
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -686,10 +686,15 @@ export default class Notifications extends Vue {
}
async checkCanShowWebPush(): Promise<boolean> {
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<void> {
@ -713,9 +718,14 @@ export default class Notifications extends Vue {
}
private async isSubscribed(): Promise<boolean> {
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<void> {