【问题标题】:The script resource is behind a redirect, which is disallowed. firebase cloud messaging脚本资源位于重定向后面,这是不允许的。 firebase 云消息传递
【发布时间】:2019-12-19 05:08:44
【问题描述】:

您好,从过去一个月开始,我们的 Firebase 应用开始出现此错误。 “脚本资源位于重定向后面,这是不允许的。” 我们已经在服务器的根目录注册了 firebase-messaging-sw.js,它也在浏览器中打开。相同的代码在 localhost 中运行良好,但在公共域(cloudflare dNS)上会出现此错误

https://prnt.sc/orot3j

已经尝试过这里提到的解决方案:Firebase: change the location of the service worker

我们当前的代码:

                messaging = firebase.messaging();
                $this.setState({messaging});
                messaging.useServiceWorker(registration);
                messaging.requestPermission().then(function() {

                    $this.setState({permission:true});
                    messaging.getToken().then(function(currentToken) {
                        $this.setState({fcmtoken:currentToken});

                        resolve(currentToken);
                    });
                });
            });

firebase-messaging-sw.js 内容:

        importScripts("https://www.gstatic.com/firebasejs/5.3.0/firebase-messaging.js");
         var config = {
          apiKey: "AIzxxxxxxxxxxxxxx0",
          authDomain: "noxxxxions-7xxxd.firebaseapp.com",
          databaseURL: "https://notifications-76xxxxd.firebaseio.com",
          projectId: "nxxxxxxxxxxd",
          storageBucket: "notifixxxxxx.appspot.com",
          messagingSenderId: "90000000000"
        };
        firebase.initializeApp(config);
        var messaging = firebase.messaging();


        messaging.setBackgroundMessageHandler(function(payload) {

          var notificationTitle = "Background Message Title";
          var notificationOptions = {
            body: "Background Message body.",
            icon: "/firebase-logo.png"
          };

          return self.registration.showNotification(notificationTitle,
            notificationOptions);
        });```

【问题讨论】:

  • 谁能帮我们解决这个问题?

标签: reactjs firebase firebase-cloud-messaging


【解决方案1】:

单击该链接会导致重定向。

如果您尝试使用重定向的 url,例如:https://prnt.sc/orot3j 而不是 http://prntscr.com/orot3j

【讨论】:

  • 更改了 url 你能就这个问题提出任何解决方案吗?
猜你喜欢
  • 2017-09-05
  • 2019-07-22
  • 1970-01-01
  • 1970-01-01
  • 2021-12-02
  • 1970-01-01
  • 1970-01-01
  • 2016-05-26
相关资源
最近更新 更多