Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 聚焦选项卡时未调用firebase onMessage_Javascript_Firebase_Firebase Cloud Messaging - Fatal编程技术网

Javascript 聚焦选项卡时未调用firebase onMessage

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" },

我的目标是在pwa中实现推送通知。 为了开始使用firebase,我没有加载消息传递示例

我使用邮递员发送邮件,如:

 {
    "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]
可以查看完整的代码。 我测试了铬和边缘。 但是,我在控制台中没有看到任何弹出窗口或任何东西。 我是否需要执行其他操作来获取控制台中的数据