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:
kyuuseiryuu 2026-03-27 22:30:03 +09:00
parent 7cbf6562f0
commit b62fed7bac

View File

@ -22,6 +22,7 @@ export const getFirebaseApp = () => {
};
export const initServiceWorker = async () => {
try {
if (!navigator.serviceWorker) return;
if (!firebase.registeration) {
firebase.registeration = await navigator.serviceWorker.register('/sw.js', {
@ -30,6 +31,10 @@ export const initServiceWorker = async () => {
}
console.debug('Serviceworker inited', firebase);
return firebase.registeration;
} catch(e) {
console.debug('不支持 ServiceWorker');
return null;
}
}
export const getFirebaseMessaging = () => {