【问题标题】:Service worker not setting up correctly on deployed Firebase web-app for firebase cloud messagingService Worker 未在已部署的 Firebase Web 应用上正确设置 Firebase 云消息传递
【发布时间】:2020-11-22 02:16:37
【问题描述】:

我的 Service Worker 工作得很好,可以在我的本地主机上生成令牌,但是每当我部署它时它都不起作用。如果有什么不同,我使用了 create-react-app buildpack,所以我运行 npm run build 然后 firebase deploy 来启动并运行我的应用程序(以 build 作为根文件夹)。我已经检查过了,firebase-messaging-sw.js 确实存在于我部署的版本中。 这是我在控制台中收到的错误消息:

  1. firebase-messaging-sw.js:2 未捕获的 DOMException:无法在“WorkerGlobalScope”上执行“importScripts”:“https://www.gstatic.com/firebasejs/3.4.0/firebase-messaging. js 加载失败。 在https://nearify-f2a4a.firebaseapp.com/firebase-messaging-sw.js:2:1 (匿名)@firebase-messaging-sw.js:2

  2. 获取脚本时收到错误的 HTTP 响应代码 (404)。

  3. firebase-messaging-sw.js:2 未捕获的 DOMException:无法在“WorkerGlobalScope”上执行“importScripts”:“https://www.gstatic.com/firebasejs/3.4.0/firebase-messaging. js 加载失败。 在https://nearify-f2a4a.firebaseapp.com/firebase-messaging-sw.js:2:1 (匿名)@ firebase-messaging-sw.js:2 获取脚本时收到错误的 HTTP 响应代码 (404)。

【问题讨论】:

    标签: reactjs firebase firebase-cloud-messaging firebase-hosting


    【解决方案1】:

    问题在于导入脚本,我们应该改用“/_/”导入脚本,而不是尝试使用“https://”等。您可以在此处找到更多信息:https://firebase.google.com/docs/cloud-messaging/js/receive

    【讨论】:

    • 你能详细说明/_/是什么意思
    猜你喜欢
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    • 2021-01-29
    • 2016-11-05
    • 2020-11-07
    相关资源
    最近更新 更多