Home > Software engineering >  Persist IndexedDB in cordova app when app updates
Persist IndexedDB in cordova app when app updates

Time:11-01

I have an Android app built using Cordova. Version 1, which has been released for a while, stores some data using IndexedDB. I’m ready to release the next version but updating the app wipes all the data stored in IndexedDB.

What I noticed is that on Version 1, it uses cordova-android@^7.0.0 which uses file:// as the security origin (I knew this from the debug tool). Then, on the next version, I upgrade the cordova to cordova-android@^9.0.0. Now, it is using http://localhost as the security origin.

cordova-android@^7.0.0 cordova-android@^9.0.0

is there a way to migrate all the existing data when the app upgraded?

CodePudding user response:

The only way would have been, in the previous version, to dump JSON data into a local file as a back up, then on the next upgrade, check if the local file is present and load/inject it back to IndexedDB. But it's probably too late now... I don't see a solution as you are set up right now...

CodePudding user response:

I just upgraded from cordova-android@^8.1.0 to cordova-android@^11.0.0 and had the same issue you described. I didn't find any solution or question besides this thread. Just before giving up, I looked at cordova source and logic, and saw that there is a parameter called "AndroidInsecureFileModeEnabled". I set it to true on the config.xml and it worked! The app came back to use "file://" as the security origin, so after upgrade the app still logged in.

Later I searched about this param and found some docs about it so it's important to know the insecure impact of setting it to true. For now I don't have any choice but to use it. I hope that it doesn't affect or can break anything else...

Let me know if it helps.

enter image description here

enter image description here

  • Related