nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
640 stars 98 forks source link

Firebase analytics - Environment doesn't support IndexedDB #323

Closed eljass closed 3 years ago

eljass commented 3 years ago

Version

@nuxtjs/firebase: ^6.1.1 firebase: ^7.23.0 nuxt: ^2.14.6

Steps to reproduce

Try to initialize analytics on browser not supporting IndexedDB. Can I use

What is Expected?

Analytics should initialize only on supported environment. Firebase suggest to wrap initialization of analytics in analytics.isSupported() to prevent initialization in unsupported environments.

What is actually happening?

@firebase/analytics: Analytics: Environment doesn't support IndexedDB: Database deleted by request of the user. Wrap initialization of analytics in analytics.isSupported() to prevent initialization in unsupported environments (analytics/invalid-indexedDB-context).

Error: UnknownError: Database deleted by request of the user

Solution(?)

Seems to be easily fixed by adding condition for initialization: /lib/plugins/main.js line 305 - 321

firebase.analytics.isSupported().then((isSupported) => {
  if (isSupported) {
    const fireAnalytics = session.analytics()
    const fireAnalyticsObj = firebase.analytics
    inject('fireAnalytics', fireAnalytics)
    inject('fireAnalyticsObj', fireAnalyticsObj)
    <% if (typeof options.services.analytics === 'object') { %>
      <% if ('collectionEnabled' in options.services.analytics) { %>
         // In development we want to disable analytics collection
        fireAnalytics.setAnalyticsCollectionEnabled(<%= !!options.services.analytics.collectionEnabled %>)
      <% } %>
    <% } %>
  }
)}

Firebase reference

lupas commented 3 years ago

Hey @eljass

Thanks for the issue, I'll have a look at it and most probably fix it for v7.0.0

lupas commented 3 years ago

Hey @eljass

Fixed this with https://github.com/nuxt-community/firebase-module/commit/52ec6efa6c1cfbd0ddaac4a73676f948da4d807e which will be shipped with v7.0.0 in the coming days.

Thanks for the issue - appreciate it!