ionic-team / cordova-plugin-ionic-webview

Web View plugin for Cordova, specialized for Ionic apps.
Apache License 2.0
484 stars 390 forks source link

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

Open masimplo opened 5 years ago

masimplo commented 5 years ago

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.

ippeiukai commented 5 years ago

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?

DavidWiesner commented 5 years ago

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

timbru31 commented 5 years ago

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

masimplo commented 5 years ago

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

timbru31 commented 5 years ago

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?

simonwatt commented 5 years ago

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.

masimplo commented 5 years ago

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.

mlynch commented 5 years ago

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.

masimplo commented 5 years ago

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.

mlynch commented 5 years ago

👍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

timbru31 commented 5 years ago

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

simonwatt commented 5 years ago

👍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

krishnagopinath commented 5 years ago

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.

timbru31 commented 5 years ago

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

krishnagopinath commented 5 years ago

@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

simonwatt commented 5 years ago

@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.

krishnagopinath commented 5 years ago

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

OJ7 commented 4 years ago

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.

graphefruit commented 4 years ago

Is there any more information about this migration?

mtshare commented 4 years ago

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?

OJ7 commented 4 years ago

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.

rajashekaranugu commented 4 years ago

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

C-ForamRaiyani commented 2 years ago

@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.