refactor(firebase): add try-catch for service worker registration
Wrap the service worker registration logic in a try-catch block to prevent uncaught exceptions when Service Workers are not supported or fail to load. Log a debug message on failure and return null instead of propagating the error. This improves application robustness in environments without Service Worker support.
This commit is contained in:
parent
7cbf6562f0
commit
b62fed7bac
@ -22,14 +22,19 @@ export const getFirebaseApp = () => {
|
||||
};
|
||||
|
||||
export const initServiceWorker = async () => {
|
||||
if (!navigator.serviceWorker) return;
|
||||
if (!firebase.registeration) {
|
||||
firebase.registeration = await navigator.serviceWorker.register('/sw.js', {
|
||||
scope: '/',
|
||||
});
|
||||
try {
|
||||
if (!navigator.serviceWorker) return;
|
||||
if (!firebase.registeration) {
|
||||
firebase.registeration = await navigator.serviceWorker.register('/sw.js', {
|
||||
scope: '/',
|
||||
});
|
||||
}
|
||||
console.debug('Serviceworker inited', firebase);
|
||||
return firebase.registeration;
|
||||
} catch(e) {
|
||||
console.debug('不支持 ServiceWorker');
|
||||
return null;
|
||||
}
|
||||
console.debug('Serviceworker inited', firebase);
|
||||
return firebase.registeration;
|
||||
}
|
||||
|
||||
export const getFirebaseMessaging = () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user