For*_*stG 8 javascript firebase flutter firebase-cloud-messaging
我有一个带有 FlutterFire 的功能齐全的 Flutter 应用程序,其中 android 包工作得很好,但 Web 客户端在启动时给出了一个奇怪的错误。我也无法使用 flutterfire 调用任何 firebase 函数。(简单的 firebase 查询就可以了)
\n启动时或尝试调用时的错误消息FirebaseFunctions.instance.httpsCallabe(\'...:
:1337/dart_sdk.js:7025 Uncaught (in promise) Error: [firebase_messaging/failed-service-worker-registration] Messaging: \nWe are unable to register the default service worker. \nFailed to register a ServiceWorker for scope (\'http://localhost:1337/firebase-cloud-messaging-push-scope\') with script (\'http://localhost:1337/firebase-messaging-sw.js\'): The script has an unsupported MIME type (\'text/html\'). .\n at Object.throw_ [as throw] (:1337/dart_sdk.js:5334)\n at firebase_messaging_web.FirebaseMessagingWeb.new.getToken (:1337/packages/firebase_messaging_web/firebase_messaging_web.dart.lib.js:112)\n at getToken.throw (<anonymous>)\n at :1337/dart_sdk.js:39038\n at _RootZone.runBinary (:1337/dart_sdk.js:38894)\n at _FutureListener.thenAwait.handleError (:1337/dart_sdk.js:33887)\n at handleError (:1337/dart_sdk.js:34451)\n at Function._propagateToListeners (:1337/dart_sdk.js:34477)\n at _Future.new.[_completeError] (:1337/dart_sdk.js:34323)\n at async._AsyncCallbackEntry.new.callback (:1337/dart_sdk.js:34362)\n at Object._microtaskLoop (:1337/dart_sdk.js:39176)\n at _startMicrotaskLoop (:1337/dart_sdk.js:39182)\n at :1337/dart_sdk.js:34689\nRun Code Online (Sandbox Code Playgroud)\n我没有 firebase-messaging-sw.js文件。我只做了文档建议的操作https://firebase.flutter.dev/docs/messaging/overview/#5-web-only-add-the-sdk。
\n我的index.html:
\n<!DOCTYPE html>\n<html>\n<head>\n...\n\n <!-- The core Firebase JS SDK is always required and must be listed first -->\n <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>\n <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-auth.js"></script>\n <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>\n <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-messaging.js"></script>\n <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-functions.js"></script>\n\n\n <script>\n // Your web app\'s Firebase configuration\n var firebaseConfig = {\n apiKey: "****",\n authDomain: "*****",\n databaseURL: "*****",\n projectId: "*****",\n storageBucket: "*****",\n messagingSenderId: "*****",\n appId: "*****"\n };\n // Initialize Firebase\n firebase.initializeApp(firebaseConfig);\n </script>\n</head>\n<body>\n<script >\n if (\'serviceWorker\' in navigator) {\n window.addEventListener(\'flutter-first-frame\', function () {\n navigator.serviceWorker.register(\'flutter_service_worker.js\');\n });\n }\n</script>\n <script src="main.dart.js" type="application/javascript"></script>\n</body>\n</html>\n\nRun Code Online (Sandbox Code Playgroud)\n颤医生:
\n$ flutter doctor\nDoctor summary (to see all details, run flutter doctor -v):\n[\xe2\x9c\x93] Flutter (Channel stable, 2.0.3, on Linux, locale en_US.UTF-8)\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
17992 次 |
| 最近记录: |