Javascript 聚焦选项卡时未调用firebase onMessage
我的目标是在pwa中实现推送通知。 为了开始使用firebase,我没有加载消息传递示例 我使用邮递员发送邮件,如:Javascript 聚焦选项卡时未调用firebase onMessage,javascript,firebase,firebase-cloud-messaging,Javascript,Firebase,Firebase Cloud Messaging,我的目标是在pwa中实现推送通知。 为了开始使用firebase,我没有加载消息传递示例 我使用邮递员发送邮件,如: { "notification": { "title": "Alarm", "body": "Temperature to high!", "icon": "https://www.somewebsite.com/someimage.jpg", "click_action": "http://localhost:8081" },
{
"notification": {
"title": "Alarm",
"body": "Temperature to high!",
"icon": "https://www.somewebsite.com/someimage.jpg",
"click_action": "http://localhost:8081"
},
"data":{
"code": "a3545gae"
},
"to": "secrettokengBuX9NcFiIvmsM2lSoZlcnMWr5_Ldekta9Kl234vIqTzy7WXeioamyLdL7bYCnDCXBYJIsNrKZlUIct9VDLfjQrdmGZsefJF8KJdc_"
}
我用firebase-p 8081运行我的应用程序,我得到了预期的网站,它运行在端口8081上。
当我发送发送通知的post请求时,我没有打开该页面的浏览器选项卡,通知将按预期显示。
当我打开了一个标签页,并且发送了一个post请求时,什么也没发生,我只是在发送一条被调用的消息
// [START receive_message]
// Handle incoming messages. Called when:
// - a message is received while the app has focus
// - the user clicks on an app notification created by a service worker
// `messaging.setBackgroundMessageHandler` handler.
messaging.onMessage((payload) => {
console.log('Message received. ', payload);
// [START_EXCLUDE]
// Update the UI to include the received message.
appendMessage(payload);
// [END_EXCLUDE]
});
// [END receive_message]
可以查看完整的代码。
我测试了铬和边缘。
但是,我在控制台中没有看到任何弹出窗口或任何东西。
我是否需要执行其他操作来获取控制台中的数据