服务工作人员未在已部署的Firebase web应用程序上正确设置Firebase云消息



我的服务工作者工作得很好,可以在本地主机上生成令牌,但无论何时部署它都不起作用。如果有区别的话,我使用了create-react-app-buildpack,所以我运行npm-run-build,然后运行firebase-deploy来启动和运行我的应用程序(build作为根文件夹(。我已经检查过了,firebase-messaging-sw.js在我部署的版本中确实存在。以下是我在控制台中收到的错误消息:

  1. firebase消息传递sw.js:2 Uncaught 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消息软件.js:2

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

  3. firebase消息传递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(。

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

相关内容

最新更新