cordova-plugin-ionic-webview icon indicating copy to clipboard operation
cordova-plugin-ionic-webview copied to clipboard

Upgrading from 1.x to 2.x loses indexeddb data on Android

Open masimplo opened this issue 6 years ago • 23 comments

I am using PouchDB to persist data on Android using indexeddb as the persistence adapter. Upgrading webview from 1.x to 2.x loses all data. I understand that this webview is used for the first time for Android as it was previously only used for iOS, but there should be a way to keep existing data when upgrading.

masimplo avatar Oct 01 '18 10:10 masimplo

The problem is not just IndexedDB, but localStorage as well (already reported as #185, but was closed as duplicate of this). I suspect WebSQL as well.

Is there any workaround? Would it make sense to migrate to cordova-sqlite-storage from localStorage before upgrading to 2.x? Could we enable this plugin with iOS build only somehow?

ippeiukai avatar Oct 10 '18 11:10 ippeiukai

There should be a warning in the migration section in the Readme about this issue.

DavidWiesner avatar Nov 09 '18 05:11 DavidWiesner

This is critical for us, since our generated orders of the users are stored in the IndexedDB.
Any update from Ionic?

timbru31 avatar Nov 20 '18 10:11 timbru31

Is this still the case when upgrading from 1.x to 3.x?

masimplo avatar Jan 07 '19 20:01 masimplo

Looking at the commit history since November 2018, yes this should be an issue. @ionic-team - given the recent security alert (https://ionic.zendesk.com/hc/en-us/articles/360015176994-2019-01-03-Security-Alert-for-cordova-plugin-ionic-webview) what are the steps v1 users should take?

timbru31 avatar Jan 07 '19 20:01 timbru31

Is this still the case when upgrading from 1.x to 3.x?

I just did a test after upgrading from 2.x to 3.1.1 and all my localStorage and IndexedDB data seems to be gone. Note the comment on here: https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/165#issuecomment-444967835_ "Sadly going from http:// to ionic:// scheme causes the current localStorage/IndexedDB to be lost as the url changes."

As 1.x to 3.x will change to use ionic:// scheme I assume it will have the same problem.

@jcesarmobile My understanding is you were talking about when moving from an earlier 2.x to 2.3.0... but I'm assuming there is still no plans to fix this on a future 3.x version? Just want to double check before I go ahead with a release using 3.1.1 as I'd really rather not have all users lose this data! Upgrading to use ionic:// scheme instead of the webserver on 3.x will likely fix many iOS 12 issues I was having, but losing IndexedDB data when migrating really is annoying.

simonwatt avatar Jan 23 '19 00:01 simonwatt

It is more than annoying for some apps. In our app, losing the locally stored data is a show stopper. We are now stuck in a version with a security issue and there is no available migration path to the newer versions. At least there should exist a version that both old and new filesystems could be access at the same time and allow us to copy the data over, if an automatic move to the new scheme is not possible.

masimplo avatar Feb 05 '19 17:02 masimplo

Clearly we need to be more up front that apps should not use indexeddb or local storage if persistent data storage is a requirement. This is why our Storage library uses SQLite for iOS and Android, as that data is stored in a file and will not be lost in situations like this or reclaimed by the OS: https://ionicframework.com/docs/building/storage

Unfortunately, we're not really sure if there's a way to transition over data. We recommend you doing that yourself by releasing an update that moves your data off of indexeddb/local storage and into sqlite, and then when upgrading the webview you can either pull that data back, or better yet, keep using sqlite instead.

mlynch avatar Feb 05 '19 18:02 mlynch

We do indeed use sqlite in iOS as it is much more stable than indexeddb on safari. But on Android I always thought the recommendation was to use indexeddb. We are actually using PouchDb as an abstraction layer and use the cordova sqlite adapter for iOS and the bundled indexeddb adapter for Android. I remember running into some issue when using sqlite with android back in the day (not sure if it was performance or something more serious). Under the light of your latest statement though, I think it is time I revisit my notes about why we made that choice and find out if it is now reversible. Thanks for the input Max.

masimplo avatar Feb 05 '19 18:02 masimplo

👍it might very well be possible to do a migration here. This is a tool we used for going from UIWebView to WKWebView: https://github.com/ionic-team/cordova-plugin-migrate-localstorage/

Unsure about indexeddb. Any input/expertise from others appreciated

mlynch avatar Feb 05 '19 20:02 mlynch

This seems to be iOS only, so not really a solution (yet?)

timbru31 avatar Feb 05 '19 20:02 timbru31

👍it might very well be possible to do a migration here. This is a tool we used for going from UIWebView to WKWebView: https://github.com/ionic-team/cordova-plugin-migrate-localstorage/

Unsure about indexeddb. Any input/expertise from others appreciated

Looking at the commit history on that repo, it looks like indexeddb may be supported?

https://github.com/ionic-team/cordova-plugin-migrate-localstorage/commit/a9818f2c843c5fcddfbe124f5c34e5b46c9d045f

simonwatt avatar Feb 07 '19 20:02 simonwatt

We created a plugin that solves this on Android as well -

https://github.com/pointmanhq/cordova-plugin-ionic-migrate-storage

The problem is that it only works for localStorage and WebSQL on Android. IndexedDB looks challenging to migrate because of Google's implementation of it via levelDB.

krishnagopinath avatar Feb 14 '19 13:02 krishnagopinath

Are you planning to add IndexedDB support @krishnagopinath? This could be a life saver!

timbru31 avatar Feb 14 '19 15:02 timbru31

@timbru31 IndexedDB migration could be tricky.. I started looking into it, but it relies on how the Chrome WebView implements IndexedDB protocol via leveldb. It looks like we need a nuanced effort to get it right and I don't have time right now to do the needed research.

I could be wrong, so if anyone wants to give it a try, feel free to add in a PR. I added an issue to the repository, so we could discuss it there!

https://github.com/pointmanhq/cordova-plugin-ionic-migrate-storage/issues/5

krishnagopinath avatar Feb 14 '19 16:02 krishnagopinath

@krishnagopinath Does your plugin handle migration to ionic:// scheme (as used by 3.x of cordova-plugin-ionic-webview)? Looking at the source code and documentation it appears not, but just wanted to double check.

simonwatt avatar Feb 14 '19 20:02 simonwatt

@simonwatt it does not, currently. It's being planned though.. https://github.com/pointmanhq/cordova-plugin-ionic-migrate-storage/issues/2

krishnagopinath avatar Feb 14 '19 21:02 krishnagopinath

Our team was able to get around this by using an InAppBrowser to open a file:///dummy.html, running a script to access the IndexedDB data from there, and passing it back to the Cordova WebView to migrate the data over. We previously attempted to use a variety of libraries to manually open the IndexedDB but ultimately we were not able to read the values from it properly but were successful going the InAppBrowser approach.

You can verify the data still exists by using the Chrome DevTools' Application tab to view the data from the InAppBrowser window.

OJ7 avatar Jul 30 '19 21:07 OJ7

Is there any more information about this migration?

graphefruit avatar Oct 08 '19 18:10 graphefruit

I have the same problem. After migrating to the last version (4.x) I can't access to IndexedDb from Android and iOS.

@OJ7 can you provide an example? How did you open a dummy.html from IAB?

mtshare avatar Oct 10 '19 14:10 mtshare

I've created a gist that contains the migration html, how to open it with IAB, as well as how to migrate the data into the new Ionic Storage.

OJ7 avatar Oct 15 '19 21:10 OJ7

Hi All, Am updating my app from IONIC 3 to Ionic 4, ionic-webview 1.2.1 to 4.3.1.

The App with ionic3, ionic-web-view 1.2.1 is in production. and i was saving some data in local storage. With this upgrade I was losing the saved data. can some one please suggest me a solution. how can I retrieve this data stored to local storage.

Ionic team please help us with a cleaner plugin

rajashekaranugu avatar Nov 19 '19 22:11 rajashekaranugu

@rajashekaranugu Did you find any working solution?

I'm also facing trouble with updating ionic-web-view from 1.2.1 to 5.0.0. The app could not maintain firebase's logged in user session.

C-ForamRaiyani avatar Mar 01 '22 10:03 C-ForamRaiyani