It would be great if there was a way to override the loading of a URL in the WebView.
For some apps, you’d like to only load URLs on a specific host and handle all other URLs separately (e.g. by opening the system browser). In Android I’d override shouldOverrideUrlLoading in the WebViewClient and I’m seeing that you are already implementing your own WebViewClient in Fuse.Android.Controls.WebView. Same with Fuse.iOS.Controls.WebView where you’d need to override decidePolicyForNavigationAction.
Here’s an example:
Let’s say I’m loading https://www.reddit.com in the WebView. When I click on a link that leads to reddit.com (e.g. to a comments section), it should be opened in the WebView. When the links leads off reddit.com, I’d like to not open it in the WebView but instead handle the url differently.
I agree, this would be great. This has been on my mind for a while since URL handling isn’t really something you can handle with a sledgehammer in most cases.
There are a few ways we could go about doing this, but I think the async nature of our JS layer vs the synchronous nature of the Android and iOS webview APIs for this kind of thing might make a pure JS implementation tough or even impossible. We may have to offer a Uno API for this, for instance passing a client object into the WebView via, say, <WebView><MyWebViewDelegate/></WebView> where MyWebViewDelegate is an implementor of an interface that gives you methods to override URL handling and so forth. Would this be acceptable you think?
A feature pass on the WebView is in order soon, this is one of the things that will definitely make it in there.
Any news on this feature?
I tried to force an URLChange event. On every link click I would prevent default and append a hash to the URL.
Unfortunately this only works on Android.
Hey Radu, no, unfortunately I don’t have news for you in this regard. I’ll bump it on the priority list for the feature team. This is clearly important.