为什么在调用FireBase函数时出现FCM错误 [英] Why does an FCM error appear when calling a firebase function
本文介绍了为什么在调用FireBase函数时出现FCM错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我通过AngularFire调用一个FireBase函数,如下所示:
const response = await this.aFunctions.httpsCallable<void, ResponseType>('funcName')().toPromise();
这在部署到Firebase(托管)时有效,但在本地环境中(使用ionic serve
),它会引发以下错误:
ERROR Error: Uncaught (in promise): FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:8100/firebase-cloud-messaging-push-scope') with script ('http://localhost:8100/firebase-messaging-sw.js'): A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).
FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:8100/firebase-cloud-messaging-push-scope') with script ('http://localhost:8100/firebase-messaging-sw.js'): A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).
我在这个项目中没有以任何方式使用FCM。你知道为什么会发生这种情况吗?
推荐答案
在我的案例中,我通过注释掉MessagingSenderID解决了这个问题。
firebase: {
apiKey: 'XXXXX',
authDomain: 'XXXXX',
databaseURL: 'XXXXX',
projectId: 'XXXXX',
storageBucket: 'XXXXX',
// messagingSenderId: 'XXXXX', **<== comment out this**
appId: 'XXXXX'
}
我的情况有点不同,也有些奇怪。 我需要将一个角度项目部署到Firebase托管。
编码:
const ob = this.functions.httpsCallable('api-name')({});
ob.subscribe((data)=>{
//do something here
});
错误:
FirebaseError: Messaging: We are unable to register the default service worker.......
环境:
- 本地:确定
- Firebase托管默认域(project tName.web.app):错误
- Firebase托管默认域(project tName.Firebase app.com):确定
我不知道原因,但希望它能帮助您和其他有类似问题的人。
这篇关于为什么在调用FireBase函数时出现FCM错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文