-
Notifications
You must be signed in to change notification settings - Fork 987
Description
Operating System
MacOS Sonoma 14.4.1
Environment (if applicable)
Chrome 132.0.6834.160 (Official Build) (arm64)
Firebase SDK Version
8.10.1
Firebase SDK Product(s)
Messaging
Project Tooling
React app (nextjs)
I also tried 9.0.0 on my local dev machine with localhost
Detailed Problem Description
The last known time this getToken code path worked correctly in my production environment was 1pm EST today. Around 4pm EST I noticed FCM was throwing "Unknown token" errors when trying to push notifications to my test accounts. Thinking I could reset the permission, I started trying to Reset permission then Allow permission, but now getToken is hanging forever and I can't register any more FCM tokens
Steps and code to reproduce issue
try {
const msg = await messaging()
if (!msg) {
console.error('Firebase messaging is not supported or failed to initialize')
return
}
console.log('Firebase messaging initialized successfully')
// Register service worker
if ('serviceWorker' in navigator) {
try {
console.log('Registering service worker...')
const registration = await navigator.serviceWorker.register('/firebase-messaging-sw.js')
console.log('Service worker registered successfully:', registration)
// Wait for the service worker to be ready
await navigator.serviceWorker.ready
console.log('Service worker is ready')
} catch (error) {
console.error('Failed to register service worker:', error)
return
}
} else {
console.error('Service workers are not supported in this browser')
return
}
try {
console.log('Attempting to get FCM token...')
// Add a timeout to detect hangs
const tokenPromise = getToken(msg, { vapidKey: VAPID_KEY })
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('getToken timed out after 10s')), 10000)
)
const fcmToken = await Promise.race([tokenPromise, timeoutPromise])
.catch(error => {
console.error('Error in getToken:', error)
throw error
})