所以我通过 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。你知道为什么会这样吗?
最佳答案
就我而言,我通过 解决了它注释掉messagesSenderId .
火力:{
apiKey: 'XXXXX',
authDomain: 'XXXXX',
数据库 URL: 'XXXXX',
项目 ID: 'XXXXX',
存储桶:'XXXXX',
//messagesSenderId: 'XXXXX', <== 注释掉这个
应用程序 ID:'XXXXX'
}
我的情况有点不同和奇怪。我需要将一个 Angular 项目部署到 Firebase 托管。
代码:
const ob = this.functions.httpsCallable('api-name')({});
ob.subscribe((data)=>{//在这里做点什么});
错误:
FirebaseError: Messaging: 我们无法注册默认的服务 worker ......
环境:
我不知道原因,但希望它可以帮助您和其他遇到类似问题的人。
关于angular - 为什么在调用 firebase 函数时会出现 FCM 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61641275/