相关疑难解决方法(0)

该脚本具有不受支持的 MIME 类型(“text/html”)

我正在尝试为Flutter Web 平台设置 Firebase Push 。

我复制了与各种教程中所示相同的设置并遇到以下错误,

Uncaught (in promise) Error: [firebase_messaging/failed-service-worker-registration] Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:61027/firebase-cloud-messaging-push-scope') with script ('http://localhost:61027/firebase-messaging-sw.js'): The script has an unsupported MIME type ('text/html')
Run Code Online (Sandbox Code Playgroud)

这是我的 Index.html 的摘录

<script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('flutter-first-frame', function () {
        navigator.serviceWorker.register('/flutter_service_worker.js')
        .then(function(registration) {
      // Registration was successful
      console.log('ServiceWorker registration successful with scope: ', registration.scope);
    }, function(err) {
      // registration failed :(
      console.log('ServiceWorker registration failed: ', …
Run Code Online (Sandbox Code Playgroud)

flutter firebase-cloud-messaging flutter-web

11
推荐指数
2
解决办法
1万
查看次数

FirebaseError:消息传递:我们无法注册默认服务工作者

您好,请帮帮我....感谢您的回复.................................通知许可的确。; FirebaseError:消息传递:我们无法注册默认服务工作人员。无法注册 ServiceWorker:获取脚本时收到错误的 HTTP 响应代码 (404)。(消息传递/serviceworker 注册失败)。

  <script src="https://www.gstatic.com/firebasejs/5.5.3/firebase-auth.js"></script>
Run Code Online (Sandbox Code Playgroud)
    <script>
        MsgElem = document.getElementById("msg")
        TokenElem = document.getElementById("token")
        NotisElem = document.getElementById("notis")
        ErrElem = document.getElementById("err")
        // Initialize Firebase
        // TODO: Replace with your project's customized code snippet
         var config = {
             apiKey: "AIzaSyBle95lld9XUBB5P-sn2vFciSxcIny-RQs",
             authDomain: "swapnear-f82dd.firebaseapp.com",
             databaseURL: "https://swapnear-f82dd.firebaseio.com",
             projectId: "swapnear-f82dd",
             storageBucket: "swapnear-f82dd.appspot.com",
             messagingSenderId: "390359777744"
         };
         firebase.initializeApp(config);

        const messaging = firebase.messaging();
        messaging
            .requestPermission()
            .then(function () {
                MsgElem.innerHTML = "Notification permission granted." 
                console.log("Notification permission granted.");

                // get the token in the form of promise
                return messaging.getToken() …
Run Code Online (Sandbox Code Playgroud)

jquery firebase firebase-cloud-messaging

5
推荐指数
1
解决办法
1万
查看次数