Complete the code to initialize Firebase Cloud Messaging in a web app.
const messaging = firebase.[1]();The messaging() method initializes Firebase Cloud Messaging service.
Complete the code to request permission for notifications from the user.
Notification.[1]().then(() => console.log('Permission granted'));
The requestPermission() method asks the user to allow notifications.
Fix the error in the code to get the FCM token for the device.
messaging.getToken({ vapidKey: '[1]' }).then(token => console.log(token));The vapidKey must be your public VAPID key from Firebase settings, not server or API keys.
Fill both blanks to handle incoming messages and show a notification.
messaging.onMessage(([1]) => { const notificationTitle = [2].notification.title; new Notification(notificationTitle); });
The callback parameter is commonly named payload, which contains the notification data.
Fill all three blanks to subscribe the user to a topic using the Firebase Admin SDK.
admin.messaging().subscribeToTopic([1], '[2]').then(response => { console.log('Successfully subscribed:', [3]); });
You pass the device tokens as registrationTokens, the topic name as a string, and log the response from the subscription call.