Complete the code to listen for foreground messages using Firebase Cloud Messaging.
firebase.messaging().onMessage([1]);The onMessage method expects a callback function as its argument to handle incoming messages.
Complete the code to log the notification payload when a message is received in the foreground.
firebase.messaging().onMessage(([1]) => { console.log('Message received:', [1]); });
The callback receives the message payload, which is commonly named payload.
Fix the error in the code to correctly display a notification when a foreground message arrives.
firebase.messaging().onMessage((payload) => {
new Notification([1]).show();
});The notification title is inside payload.notification.title when receiving a message.
Fill both blanks to extract the notification title and body from the payload.
const title = payload.[1].title; const body = payload.[2].body;
Both title and body are inside the notification object of the payload.
Fill all three blanks to show a notification with title, body, and icon from the payload.
const notificationOptions = {
body: payload.[1].body,
icon: payload.[2].icon
};
new Notification(payload.[3].title, notificationOptions);data instead of notification.Title, body, and icon are all inside the notification property of the payload.