-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
breaking: implement WebViewAssetLoader #1137
Conversation
Really? |
Maybe I confused this with iOS but in some cases requests from the file protocol to servers have CORS issues. This is just one of the benefits. What are the other problems the Ionic webview solves with the local server? |
CORS is a WKWebView problem, doesn't matter if you use file or a custom protocol. In Android in the other hand, using file will ignore server CORS, while using a custom protocol or http/https will require to allow the origin on the server because it's affected by CORS. benefits of ionic-webview plugin were more about the routing, and at the beginning when it uses a local server on iOS, it allowed to use |
Thank you. I got confused with Android and iOS quirks. There are some web APIs that need a https origin to work right? Maybe that's another benefit. My motivation to try that out, was that I need that origin for routing and I tried to build a proxy into that again like I did for iOS. The The 'proxy' is to solve CORS and cookie issues and can live in a fork or the Ionic or custom webview as well. The proxy plugin can be found here: https://github.com/GEDYSIntraWare/cordova-plugin-webview-proxy. The hook for plugins to plug into the assetloaders path handlers is work in progress and I will change that again. Besides that, are there reasons for and against implementing the |
I have not used file for a long time, but as far as I remember android considered file safe, so all APIs worked, but things might have changed. They also work on http://localhost (default on ionic webview) I was under the impression that WebViewAssetLoader didn’t allow to “intercept” the requests, I thought you could only point to a folder in assets and it would load whatever is there, but using a proxy wouldn’t be possible, glad to be wrong. I think we are going to need this or some other approach because when you target SDK 30 you can’t fetch file urls anymore So unless somebody proposes an alternative, this is probably the only way |
No reasons against implementing. In fact, it is a must implement feature. Google has disabled allowing access to
Additionally, it is generally discouraged to load from file protocol, hence the reason they disabled this. Setting the file access back to true was only a quick temporary fix. I was already planning to implement the Some methods are already deprecated starting from API 30. For example the |
I think we do want to do this, to resolve the issues with file URLs and API 30 and security concerns, but if we're adding an AndroidX dependency then we should also just move to the AndroidX WebView instead of the system one. I think a good way to prototype this would be to make a new pluggable webview plugin for the AndroidX webview, that can be installed in existing versions of cordova-android for testing, and then bring it in either as part of the next major or as a |
I don't think AndroidX is as big of a problem as it sounds. Plugins that don't use AndroidX is mainly because they are unmaintained, or because it's hard to use it when cordova-android doesn't enforce it's usage. A few of them are maintaining 2 versions at the same time, one with AndroidX and other with the old support libraries. So current status overloads maintainers that maintain the plugins for not breaking unmaintained plugins. Anyway, with jetifier or dave alden's plugins the problem is solved, in Capacitor 2 we moved to AndroidX and there have not been any problems with the cordova plugin compatibility, we just tell users to use jetifier. AndroidX apart, this is still a breaking change, since changing from file to https will mean data loss, so yeah, this should be targeted for next major. |
I pushed some more breaking changes with APIs that got deprecated in API level 30. Lets test it out and see if we can get rid of them. @jcesarmobile Maybe you could help me with routing for single page apps? I am not sure how to do that properly since the WebViewAssetLoader behaves a bit differently. So my Angular has a page |
I think I can pitch in here. I'm not sure if this is something that Cordova should try to solve... but for now, let's assume that Cordova should. In a "traditional" web server setup... you'd have a redirect rule so when virtual url routes are requested.. it always serves the On another note... In Cordova apps, you don't see the URL ever -- it should be perfectly fine to use hash-bashed routing strategies. Is there a strong reason why we should support virtual urls? |
Cordova definitely should not try to solve this. We don't want to be responsible for a URL rewriting layer on top of the filesystem. Hash-based routing is the only option for Cordova apps serving from local files. |
faf0c7e
to
7f3d65c
Compare
Codecov Report
@@ Coverage Diff @@
## master #1137 +/- ##
=======================================
Coverage 71.98% 71.98%
=======================================
Files 21 21
Lines 1692 1692
=======================================
Hits 1218 1218
Misses 474 474 Continue to review full report at Codecov.
|
@erisu @dpogue @NiklasMerz @breautek Any time cordova is adopting to WebAssetLoader usage? Please confirm. My app uses file:// kind of image display and setAllowFileAccess(true) is temp fix for me. https://bugs.chromium.org/p/chromium/issues/detail?id=1101250#c7 |
I think our current goals is to be completely on AndroidX for version 10, which will allow us to also incorporate WebAssetLoader. |
90750b2
to
c490050
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ok for me. 😊
Codecov Report
@@ Coverage Diff @@
## master #1137 +/- ##
==========================================
- Coverage 71.98% 71.97% -0.01%
==========================================
Files 21 21
Lines 1692 1695 +3
==========================================
+ Hits 1218 1220 +2
- Misses 474 475 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes LGTM 👍
What does this mean for apps with existing data in |
Yes that's right. Switching the from I don't know if many are still using |
Anyone using default Cordova-Android will still be using We should consider if there's any way to automatically migrate data in this case. A lot of apps aren't in a position where they'll be able to upgrade if it means data loss. |
I have a plugin that I used to migrate from crosswalk local storage containers to the normal webview storage container under an http://localhost origin I'm sure it could be adapted for this specific migration. Chrome has two different storage containers that is used, depending on the webview version (i think the switch happened around chrome 78 if i recall correctly). So the plugin will definitely have to be adapted to look for a leveldb database under the old origin, and if missing then fallback to the sqllite database. Chrome (unless if they have changed it since Chrome 80ish) will auto migrate sqllite databases to leveldb, so we don't need to worry about converting the database ourselves. I have no idea if indexeddb follows the same pattern though. https://github.com/totalpave/cordova-plugin-crosswalk-data-migration/tree/totalpave/master |
@breautek we can maybe integrate that plugin into the |
Implement AndroidX WebViewAssetLoader with hook for plugins Co-authored-by: エリス <[email protected]>
Implement AndroidX WebViewAssetLoader with hook for plugins Co-authored-by: エリス <[email protected]>
I have created an e-mail thread for this please respond there: https://lists.apache.org/thread.html/rdf5efb2f33b1ced770297326c4f9fb87a1123d93f5ca0b271b8797c7%40%3Cdev.cordova.apache.org%3E |
Implement AndroidX WebViewAssetLoader with hook for plugins Co-authored-by: エリス <[email protected]>
I'm currently not able to upgrade to version 10 as I have not yet found a way to migrate IndexedDB storage. Copying the contents of the old directories doesn't work unfortunately:
to:
Haven't figured out yet why it doesn't work. Has anyone managed to successfully migrate indexedDB? |
This is a breaking change since it requires the AndroidX dependency in cordova-android core
Platforms affected
Android
Motivation and Context
The Android Webview team suggests to use the
WebViewAssetLoader
to load local files. This PR is work in progress to show if this is possible and what needs to be considered.This has some significant benefits over using the file: scheme. Having a 'proper' origin makes routing for frameworks like Angular work etc.
Description
TODO
Closes #1135
ionic-team/cordova-plugin-ionic-webview#483
Testing
Unit Tests TODO!
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)