-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Can't use WebView with local files stored as MauiAssets on Windows #16646
Comments
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
@PureWeen I'd like to look at this issue and figure out a fix. Is there a manual or a list of directions to follow in order to set up development using the dotnet maui git repository? Thank you! |
There is a doc: https://github.com/dotnet/maui/blob/main/.github/DEVELOPMENT.md Typically my dev path is:
But, if you have any issues, read the doc and see if there is an extra step you need to do to set up any pre-reqs. |
I was able to verify the bugs using the First problem: As a workaround, I can remove the The real fix would be to recongize the re-loading of the HTML code and instead call Second problem: As a workaround, I can pass a relative URL and then it just works. I will create a PR with two changes that should fix both problems. |
Verified this on Visual Studio Enterprise 17.8.0 Preview 1.0. Repro on Windows 11 .NET 8 with below Project: First issue(Windows): The image can't be referenced. |
Just a note, the sample project does not work in Android and iOS, since it would require different base urls, but these two platforms are out of scope for this issue anyway. |
…to correctly setting the BaseUrl for an HtmlWebViewSource see also: dotnet/maui#16646 dotnet/maui#16930
Hello, I have the same issue with displaying images in html on android (image can't be referenced). Is here some progress? Thanks! |
@lukasrut this issue is only for the Windows WebView2, so it's probably best if you open a new issue for your specific problem |
Description
I'm using a
WebView
in a MAUI content page and want to reference local files. From #7672 I gather that on Windows I can use thehttps://appdir/
URL and the WindowsWebView
handler sets up a virtual folder mapping so that I can reference local files that are marked withMauiAsset
. I have two similar problems here:HtmlWebViewSource
, the BaseUrl is set to the URL but the image can't be referenced:The image file is placed correctly in the app's layout folder at build.
UrlWebViewSource
, the Windows WebView first shows an error "Hmmm… can't reach this page", then after a few seconds, reloads the page and everything works:Both bugs makes it hard to show WebView content that references local asset files.
I didn't test the other platforms, as they need a different
BaseUrl
orUrl
, and the handler doesn't need to set up a virtual host name to folder mapping.I have the feeling that calling
WebView2
'sSetVirtualHostNameToFolderMapping()
is missing at some spot. I have written a UWP Xamarin.Forms renderer that also provides platformWebView2
forXamarin.Forms.WebView
and there it works without a problem.Steps to Reproduce
I prepared a sample app, and it's the easiest to use this:
WebViewLocalFilesMauiApp
MainPage.xaml.cs
and find that the second problem case is uncommented.MainPage.xaml.cs
to use theHtmlWebViewSource
instead ofUrlWebViewSource
to reproduce the first problemUrlWebViewSource
and remove thereturn;
statement inWebView_HandlerChanged
Link to public reproduction project repository
https://github.com/vividos/SampleProjects/
Version with bug
7.0.86
Is this a regression from previous behavior? In other words, did this work before an update and now does not?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows SDK 10.0.19041
Did you find any workaround?
See steps 5 and 6 above, but it's a workaround only for the specific URL.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: