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:
parent
5c90fa9659
commit
34a6144c3a
|
@ -686,10 +686,15 @@ export default class Notifications extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkCanShowWebPush(): Promise<boolean> {
|
async checkCanShowWebPush(): Promise<boolean> {
|
||||||
|
try {
|
||||||
if (!window.isSecureContext || !("serviceWorker" in navigator))
|
if (!window.isSecureContext || !("serviceWorker" in navigator))
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
const registration = await navigator.serviceWorker.getRegistration();
|
const registration = await navigator.serviceWorker.getRegistration();
|
||||||
return registration !== undefined;
|
return registration !== undefined;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async created(): Promise<void> {
|
async created(): Promise<void> {
|
||||||
|
@ -713,9 +718,14 @@ export default class Notifications extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async isSubscribed(): Promise<boolean> {
|
private async isSubscribed(): Promise<boolean> {
|
||||||
|
try {
|
||||||
if (!("serviceWorker" in navigator)) return Promise.resolve(false);
|
if (!("serviceWorker" in navigator)) return Promise.resolve(false);
|
||||||
const registration = await navigator.serviceWorker.getRegistration();
|
const registration = await navigator.serviceWorker.getRegistration();
|
||||||
return (await registration?.pushManager?.getSubscription()) != null;
|
return (await registration?.pushManager?.getSubscription()) != null;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async deleteFeedToken(token: string): Promise<void> {
|
private async deleteFeedToken(token: string): Promise<void> {
|
||||||
|
|
Loading…
Reference in a new issue