v0.12.5 FCM bug fixes
This commit is contained in:
@@ -93,13 +93,37 @@ firebaseConfigPromise.then(() => {
|
||||
}
|
||||
});
|
||||
|
||||
// ── Raw push event (fallback diagnostic) ─────────────────────────────────────
|
||||
// Fires for every push event BEFORE the Firebase SDK handles it.
|
||||
// Log it so chrome://inspect shows whether the SW is even waking up.
|
||||
// ── Raw push event (fallback for Android) ─────────────────────────────────────
|
||||
// Android Chrome sometimes doesn't properly trigger Firebase's onBackgroundMessage
|
||||
// This fallback ensures notifications are displayed even if Firebase SDK fails
|
||||
self.addEventListener('push', (event) => {
|
||||
console.log('[SW] push event received, hasData:', !!event.data, 'text:', event.data?.text?.()?.slice(0, 120));
|
||||
// Note: Firebase compat SDK registers its own push listener and handles display.
|
||||
// This listener is diagnostic only — do not call showNotification() here.
|
||||
|
||||
// Try to handle the push event directly as a fallback
|
||||
if (event.data) {
|
||||
try {
|
||||
const data = event.data.json();
|
||||
console.log('[SW] Push data parsed:', JSON.stringify(data));
|
||||
|
||||
// If this is a Firebase message with data payload, show notification
|
||||
if (data.data || (data.title && data.body)) {
|
||||
const notificationData = data.data || data;
|
||||
return showRosterChirpNotification(notificationData);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[SW] Failed to parse push data:', e);
|
||||
// Try to show a basic notification with the raw text
|
||||
const text = event.data.text();
|
||||
if (text) {
|
||||
return self.registration.showNotification('RosterChirp', {
|
||||
body: text.slice(0, 100),
|
||||
icon: '/icons/icon-192.png',
|
||||
badge: '/icons/icon-192-maskable.png',
|
||||
tag: 'rosterchirp-fallback',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ── Notification click ────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user