Firebase Cloud Messaging 在 Mozilla Firefox 隐身模式下不起作用



Firebase 云消息在 Mozilla 中正常工作,但是当我在隐身模式下尝试相同的错误时,此错误会导致应用程序崩溃。

此浏览器不支持使用 Firebase SDK 所需的 API。(消息/不支持的浏览器(Mozilla

无论如何,我们可以通过它来处理这个问题。

"在 Firefox 中,Service Worker API 是隐藏的,当用户处于隐私浏览模式时无法使用。

来源:https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers

您不能在 Firefox 的私有模式下使用消息传递,因为它依赖于 Service Worker API。没有办法规避这一点。

您可以通过调用messaging.isSupported()来检查是否支持消息传递。示例代码:

import firebase from 'firebase/app';
import 'firebase/messaging';
if (firebase.messaging.isSupported()) {
// messaging is supported
const messaging = firebase.messaging();
} else {
// messaging is not supported
}

最新更新