Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic migration of localStorage when moving to android@10 / WebViewAssetLoader #1315

Closed
skmbr opened this issue Aug 7, 2021 · 7 comments

Comments

@skmbr
Copy link

skmbr commented Aug 7, 2021

Feature Request

Motivation Behind Feature

As per the discussion on this issue: #1137 (comment) localStorage data will no longer be accessible when the origin changes from file:// to https://localhost

Feature Description

The discussion above suggests incorporating migration of localStorage/cookies/etc from file:// to https://localhost into the core of the android platform.

I was wondering if this was in the plan, or if anyone can suggest another way of achieving this now?

@revie
Copy link

revie commented Aug 9, 2021

I'm not sure a migration option is needed. Looks like Google already thought of this when they added a "preserveLegacyExternalStorage" attribute:

https://developer.android.com/reference/android/R.attr#preserveLegacyExternalStorage

I haven't verified if it works as expected, but it seems like it's what you're looking for. Good luck!

@breautek
Copy link
Contributor

breautek commented Aug 9, 2021

I'm not sure a migration option is needed. Looks like Google already thought of this when they added a "preserveLegacyExternalStorage" attribute:

https://developer.android.com/reference/android/R.attr#preserveLegacyExternalStorage

I haven't verified if it works as expected, but it seems like it's what you're looking for. Good luck!

This is not related to the OP request whatsoever. The OP is talking about the webview's data storage containers, which are bound to the document's origin. Cordova-android@9 and earlier used a file:// scheme so the document's origin is null (or empty), but cordova-android@10 and moving forward the scheme uses https://localhost (by default), making the origin https://localhost

preserveLegacyExternalStorage is for how the app itself stores or accesses "external" storage (e.g.: public folders).

We had a discussion on how to deal with the origin changes in this mailing list thread

In a short summary, the Apache volunteer team decided not to handle data migration ourselves and decided it is up to the community users to develop a plugin to migrate the data themselves.

If you aren't ready to migrate data, then the AndroidInsecureFileModeEnabled preference flag can be set to true, which should make the platform use file:// based URLs, thus making the origin unchanged from cordova-android@9

I'm closing this request as it was already decided that Apache won't take responsibility of migrating data.

You won't be able to take this plugin as is for data migration, but you can learn a bit how to migrate local storage data by looking at the plugin sources. The two major differences is that modern chrome webviews doesn't use SQLite databases anymore, it uses LevelDB, and xwalk directories are only for users using crosswalk.

@breautek breautek closed this as completed Aug 9, 2021
@skmbr
Copy link
Author

skmbr commented Aug 9, 2021

Thanks for clearing that up @breautek

I will keep an eye out for a plugin and have a proper read through that email thread as there seem to be some discussions on migrations strategy in there too.

I might also look at migrating to something like https://github.com/TheCocoaProject/cordova-plugin-nativestorage and then enable WebViewAssetLoader once I'm happy enough users are migrated.

Thanks for your help!

@breautek
Copy link
Contributor

breautek commented Aug 9, 2021

Yah, personally I would move away from relying on browser storage, and part of your migration strategy might be using that native storage plugin.

In my apps, I've migrated to either using flat files using cordova-plugin-file, or SQLite using an sqlite plugin -- depending on the complexity of the data being stored in the app.

@skmbr
Copy link
Author

skmbr commented Aug 9, 2021

It's fairly simple, just settings mainly, so SQLite is definitely an option, especially as the owner of the nativestorage plugin has said he doesn't have time to actively maintain it.

@roitto
Copy link

roitto commented Aug 18, 2021

If the AndroidInsecureFileModeEnabled attribute is set to true, will the play store still accept the application updates?

@breautek
Copy link
Contributor

If the AndroidInsecureFileModeEnabled attribute is set to true, will the play store still accept the application updates?

For the foreseeable future, I cannot see why not. By default, the webview always used local file paths and everyone running cordova-android@9 and earlier would be using the local filepaths as well. Google hasn't gave any signal that it will start rejecting these apps because they are using file:// based paths.

They are however recommend people to start using the web asset loader, which is what cordova-android@10 implements and uses by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants