This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
[firebase_analytics] Adblocker crashes the whole app. #335
Labels
Comments
Thanks for the workaround, it was driving me nuts |
Thank you so much for this workaround. |
The previously proposed fixes are okay, however, they simply make the app not crash. Firebase Analytics will still be broken. Here is a script that you can insert in your <!--
We need to create a mock for Firebase Analytics that ensures that it *does not matter **when***
the JS library is loaded. This is because Google Tag Manager will load firebase-analytics.js
and this 1. happens asynchronously and 2. only after the user consented.
The firebase.dart Dart library will crash if the firebase.analytics object does not exist,
which is why this is absolutely crucial for starting the app.
https://github.com/FirebaseExtended/firebase-dart/issues/335#issuecomment-797003830
-->
<script>
// This mock ensures that if the firebase_analytics Flutter plugin uses this mock as its
// instance (which does not change over time), the plugin will *still* be able to reach out
// to the actual firebase.analytics() instance because the object will be overridden once the
// firebase-analytics.js library is loaded in.
firebase.analytics = function () {
return {
mock: true,
app: function () {
var instance = firebase.analytics()
// Prevent infinite recursion if the real instance has not yet been loaded.
if (instance.mock === true) return
return instance.app
},
logEvent: function () {
var instance = firebase.analytics()
if (instance.mock === true) return
return instance.logEvent(...arguments)
},
setAnalyticsCollectionEnabled: function () {
var instance = firebase.analytics()
if (instance.mock === true) return
return instance.setAnalyticsCollectionEnabled(...arguments)
},
setCurrentScreen: function () {
var instance = firebase.analytics()
if (instance.mock === true) return
return instance.setCurrentScreen(...arguments)
},
setUserId: function () {
var instance = firebase.analytics()
if (instance.mock === true) return
return instance.setUserId(...arguments)
},
setUserProperties: function () {
var instance = firebase.analytics()
if (instance.mock === true) return
return instance.setUserProperties(...arguments)
},
}
}
</script> |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
A Flutter Web app will crash if the user has an adblocker enabled and
<script src="https://www.gstatic.com/firebasejs/.../firebase-analytics.js"></script>
can't be loaded. No widget is drawn, it crashes during the registerPlugin phase.To Reproduce
Steps to reproduce the behavior:
flutter run web
Expected behavior
App should still at least launch (even though analytics won't work obviously).
Additional context
Temporary solution is to add this anywhere before loading main.js:
Flutter doctor
Run
flutter doctor
and paste the output below:This issue was originally created here:
firebase/flutterfire#3346
The text was updated successfully, but these errors were encountered: