-
Notifications
You must be signed in to change notification settings - Fork 742
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
The implementation of WebView SetVirtualHostNameToFolderMapping on Android is not aligned with WinUI3 #18930
Comments
Yes, I noticed that when I previously worked on WebView support for WPF. To me, it seemed like a limitation of the native Android API. The only way around this is that we alter the HTML ourselves, but not trivial to "correctly" support all the scenarios as in WinUI. Note: for WPF. I added a new interface, |
The implementation is not complex but I'm not familiar with Uno dev process and the current architecture of Uno Webview, otherwise I will submit a patch. Some demonstration code(toy code):
|
I didn't came across |
This like should be implemented around here:
and here: uno/src/Uno.UI/UI/Xaml/Controls/WebView/Native/Android/NativeWebViewWrapper.Android.cs Line 17 in 58e477b
|
There are 2 scenes the hostname is used:
WinUI3 support 1 and 2. The root cause is in InternalClient To support scene 1, InternalClient overrode ShouldOverrideUrlLoading and then called ProcessNavigation in uno/src/Uno.UI/UI/Xaml/Controls/WebView/Native/Android/NativeWebViewWrapper.Android.cs To support scene 2, InternalClient has to override shouldInterceptRequest |
Due to the same issue, the HTML tag |
For IOS, setURLSchemeHandler could be used for interpreting web resource loading. |
Workaround: A little slow but it works, with more flexibility. |
Current behavior
The virtual hostname is mapped for navigation urls, but not for web resources(css, js, etc.)
For
web.CoreWebView2.SetVirtualHostNameToFolderMapping( "anyhost", "Htmls", CoreWebView2HostResourceAccessKind.Allow);
A html file containing
<img src="http://anyhost/img.png">
will fail to load the image on Android, but it works as expected on Windows 11.Expected behavior
The hostname mapped by SetVirtualHostNameToFolderMapping gets resolved when loading CSS and images.
How to reproduce it (as minimally and precisely as possible)
The issue is in https://github.com/unoplatform/uno/blob/master/src/Uno.UI/UI/Xaml/Controls/WebView/Native/Android/InternalWebClient.Android.cs
InternalClient needs to implement shouldInterceptRequest and then lookup _coreWebView.HostToFolderMap
Workaround
No workaround
Works on UWP/WinUI
None
Environment
Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
NuGet package version(s)
Affected platforms
Android
IDE
Visual Studio 2022
IDE version
2022 17.12
Relevant plugins
Not relative
Anything else we need to know?
Does the issue exist on Ios and Macos? I haven't tested it yet.
The text was updated successfully, but these errors were encountered: