firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Firestore persistence isAvailable() check should exclude iOS Safari, Android 4.4, etc.

Open nathanfan46 opened this issue 8 years ago • 14 comments

[REQUIRED] Describe your environment

  • Operating System version: iOS 9.3.5
  • Firebase SDK version: 4.8.0
  • Firebase Product: firestore

[REQUIRED] Describe the problem

When enable persistence, iPad mini keep showing following error messages: unadjustednonraw_thumb_2

Steps to reproduce:

Just enable persistence

AngularFirestoreModule.enablePersistence()

Relevant Code:

// TODO(you): code here to reproduce the problem

nathanfan46 avatar Jan 16 '18 20:01 nathanfan46

I have been seeing the same issue for a while now. Is there any fix planned?

ghost avatar Feb 18 '18 08:02 ghost

@nathanfan46 Can you get us some code, or a sample repo to illustrate the problem?

jshcrowthe avatar Feb 20 '18 18:02 jshcrowthe

We rely on IndexedDB which is unfortunately not available in Safari 9. The right "fix" here is to expand our isAvailable() check here [https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/local/simple_db.ts#L85] to detect Safari 9 so we gracefully fail to enable persistence instead of crashing... We'll take a look at making this change in an upcoming release.

mikelehen avatar Feb 20 '18 21:02 mikelehen

@jshcrowthe I created a simple ionic project with AngularFirestoreModule.enablePersistence() you can reproduce the issue by running command ionic cordova run ios -lcs https://github.com/nathanfan46/rttest1

@mikelehen Thank you for the response, it would be better to not having persistence than crash.

nathanfan46 avatar Feb 20 '18 22:02 nathanfan46

I can confirm the same issue on Android 4.4 (Android 5 and above all working fine)! If I enable persistence firestore is not working. If I disable it, everything works fine. I check for IndexedDb and he returns that this is available. Is there maybe another reason why enable persistence causes the issue?

paulstelzer avatar Mar 18 '18 10:03 paulstelzer

@paulstelzer Unfortunately my guess is the Android 4.4 device you're using only has partial IndexedDB support. I see reference to some devices that define IndexedDB but is lacking some features (e.g. https://gist.github.com/nolanlawson/40f59d1d718d9c84c5cb).

This likely means we need to improve our isAvailable() check to exclude these devices that don't have sufficiently full IndexedDB support (similar to our plan for Safari 9).

mikelehen avatar Mar 18 '18 20:03 mikelehen

following

sengoontoh avatar Aug 30 '18 17:08 sengoontoh

@mikelehen : Is this issue fixed? I have not been able to enable offline persistence in my web app due to this issue. Please help.

ghost avatar Jan 22 '19 03:01 ghost

I don't know if this always fits, but you can check for navigator.serviceWorker. If this is available, you can activate persistence, otherwise not. This seems to work good for me

export function FirestorePersistenceEnabler() {
  console.log('FirestorePersistenceEnabler', navigator.serviceWorker);

  if (navigator.serviceWorker === undefined) {
    return false;
  }
  return true;
}

paulstelzer avatar Jan 22 '19 08:01 paulstelzer

We haven't fixed this. PRs welcome. It should just be a matter of updating this check: https://github.com/firebase/firebase-js-sdk/blob/fe48712fd9f0d1e1cd05bb2b706de5302d5c7d6e/packages/firestore/src/local/simple_db.ts#L132

mikelehen avatar Jan 22 '19 20:01 mikelehen

Hello @mikelehn I have a Cordova-app for Android and iOS. I need to ship my app only to Android and iOS versions compatible with Firestore offline support for Firebase JS SDK.

  1. Which Android version and up should I target?
  2. Which iOS version and up should I target?

mesqueeb avatar Mar 20 '19 02:03 mesqueeb

@mesqueeb Sorry, I don't know anything more than is captured in this github issue. Your best bet will probably be to test for yourself so you can be sure your app works as desired.

mikelehen avatar Mar 20 '19 15:03 mikelehen

@mesqueeb

A list of supported browsers and OS versions can be found here: https://caniuse.com/#feat=indexeddb

thebrianchen avatar Apr 16 '19 17:04 thebrianchen

Fixed in #1703, which will be included in the next SDK release.

iOS Safari for versions < iOS 10 and Android OS < 4.5 will default to not enabling persistence.

thebrianchen avatar Apr 17 '19 22:04 thebrianchen