【问题标题】:Firebase web push notifications working on localhost but not in dev environmentFirebase 网络推送通知在本地主机上工作,但在开发环境中不工作
【发布时间】:2018-03-05 06:38:41
【问题描述】:

我有一个基于simply-notify 的简单网络通知应用程序。 Here 是订阅推送通知的订阅页面,here 是发送消息的仪表板。

当标签页、浏览器或应用程序关闭时,推送通知会起作用。但是,我正在尝试在运行选项卡,浏览器或应用程序时接收通知,而不聚焦和专注。我已经尝试了onMessagesetBackgroundMessageHandler 方法,但它没有像我希望的那样工作。我试过在本地运行它,我收到了推送通知,没有任何问题。希望有人能帮忙。

firebase-messaging-sw.js

importScripts('/__/firebase/3.8.0/firebase-app.js');
importScripts('/__/firebase/3.8.0/firebase-messaging.js');
importScripts('/__/firebase/init.js');

const messaging = firebase.messaging();

self.addEventListener('message', event => {
    if (event.data.type === 'received_message_inactive_tab') {
        const object = // turn payload into notifications object;
        self.registration.showNotification(object.title, object.options);
    }
});

【问题讨论】:

  • 也许您需要将开发环境作为白名单域包含在内?我有一段时间没有使用 Firebase,所以只能猜测。可能是您需要做的事情。
  • @Chrillewoodz,已经完成了。否则,登录后它甚至不会继续

标签: javascript firebase firebase-cloud-messaging service-worker firebase-notifications


【解决方案1】:

Firebase 推送通知可在 localhost 或 https 中使用。 您的应用程序在 localhost 中运行良好。那么在您的开发环境中,您网站的托管/部署 url 是什么?

尝试将其设为 https:// 并验证。

【讨论】:

  • 它托管在 Firebase 中。现在一切正常。我想我只是使用了错误的事件侦听器,并期望即使在浏览器打开时也会弹出系统通知。
猜你喜欢
  • 2018-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-16
  • 2019-06-04
  • 1970-01-01
  • 2013-01-14
相关资源
最近更新 更多