Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

[firebase_analytics] Adblocker crashes the whole app. #335

@ciriousjoker

Description

@ciriousjoker

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:

  1. Create default app and add firebase_analytics as a dependency
  2. Skip the part where you would normally set up the script tags
  3. 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:

// Add stub so the app doesn't crash when an adblocker is active
if (typeof firebase.analytics !== "function") {
    firebase.analytics = () => console.log("Adblocker detected. Created fake analytics so the app doesn't crash.");
}

Flutter doctor
Run flutter doctor and paste the output below:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, 1.19.0-4.1.pre, on macOS 11.0 20A5343i, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[!] Xcode - develop for iOS and macOS (Xcode 11.6)
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install:
        sudo gem install cocoapods
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.48.1)
[✓] Connected device (2 available)

! Doctor found issues in 1 category.

This issue was originally created here:
firebase/flutterfire#3346

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions