maui
maui copied to clipboard
Maui iOS failing to load local resources in using WebView Source
Description
I would like to load local html content in a WebView. Assuming the file was named data.html and was packaged correctly then
<WebView Source="data.html" />
works on windows and android however it fails on iOS with a uri format exception.
This appears to be because the windows and android versions handle relative uri paths while the iOS one does not. Windows: https://github.com/dotnet/maui/blob/0a07dab607fba5839ad31d7165bfea070229455d/src/Core/src/Platform/Windows/MauiWebView.cs#L122 Android: https://github.com/dotnet/maui/blob/0a07dab607fba5839ad31d7165bfea070229455d/src/Core/src/Platform/Android/MauiWebView.cs#L38
The iOS one does a new Uri() directly which will fail if the uri is not an absolute path. https://github.com/dotnet/maui/blob/0a07dab607fba5839ad31d7165bfea070229455d/src/Core/src/Platform/iOS/MauiWKWebView.cs#L93
Thus that line throws an exceptions which kills the application.
0x88 in System.Uri.CreateThis C#
0x21 in System.Uri..ctor C#
0x62 in Microsoft.Maui.Platform.MauiWKWebView.LoadUrl C#
0x7 in Microsoft.Maui.Controls.UrlWebViewSource.Load C#
0x10 in Microsoft.Maui.Platform.WebViewExtensions.UpdateSource C#
0x19 in Microsoft.Maui.Handlers.WebViewHandler.MapSource C#
0x21 in Microsoft.Maui.PropertyMapper<Microsoft.Maui.IWebView,Microsoft.Maui.Handlers.IWebViewHandler>. C#
0x18 in Microsoft.Maui.PropertyMapper.UpdatePropertyCore C#
0x1D in Microsoft.Maui.PropertyMapper.UpdateProperties C#
0xCB in Microsoft.Maui.Handlers.ElementHandler.SetVirtualView C#
0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IWebView,WebKit.WKWebView>.SetVirtualView C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IWebView,WebKit.WKWebView>.SetVirtualView C#
0x65 in Microsoft.Maui.Controls.Element.SetHandler C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform C#
0xB2 in Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutView>.SetVirtualView C#
0x65 in Microsoft.Maui.Controls.Element.SetHandler C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform C#
0x13 in Telerik.Maui.RadSideDrawerExtensions.UpdateMainContent C#
0xC in Telerik.Maui.Handlers.RadSideDrawerHandler.MapMainContent C#
0x21 in Microsoft.Maui.PropertyMapper<Telerik.Maui.IRadSideDrawer,Telerik.Maui.Handlers.RadSideDrawerHandler>. C#
0x18 in Microsoft.Maui.PropertyMapper.UpdatePropertyCore C#
0x1D in Microsoft.Maui.PropertyMapper.UpdateProperties C#
0xCB in Microsoft.Maui.Handlers.ElementHandler.SetVirtualView C#
0x2 in Microsoft.Maui.Handlers.ViewHandler<Telerik.Maui.IRadSideDrawer,TelerikUI.TKSideDrawerView>.SetVirtualView C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Telerik.Maui.IRadSideDrawer,TelerikUI.TKSideDrawerView>.SetVirtualView C#
0x65 in Microsoft.Maui.Controls.Element.SetHandler C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform C#
0xB2 in Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutView>.SetVirtualView C#
0x65 in Microsoft.Maui.Controls.Element.SetHandler C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform C#
0xB2 in Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutView>.SetVirtualView C#
0x65 in Microsoft.Maui.Controls.Element.SetHandler C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform C#
0x60 in Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent C#
0x1 in Microsoft.Maui.Handlers.ContentViewHandler.MapContent C#
0x21 in Microsoft.Maui.PropertyMapper<Microsoft.Maui.IContentView,Microsoft.Maui.Handlers.IContentViewHandler>. C#
0x18 in Microsoft.Maui.PropertyMapper.UpdatePropertyCore C#
0x1D in Microsoft.Maui.PropertyMapper.UpdateProperties C#
0xCB in Microsoft.Maui.Handlers.ElementHandler.SetVirtualView C#
0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IContentView,Microsoft.Maui.Platform.ContentView>.SetVirtualView C#
0x2 in Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView C#
0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IContentView,Microsoft.Maui.Platform.ContentView>.SetVirtualView C#
0x65 in Microsoft.Maui.Controls.Element.SetHandler C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler C#
0x2 in Microsoft.Maui.Platform.ViewExtensions.ToHandler C#
0x19 in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.SetPageRenderer C#
0xA1 in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.LoadRenderers C#
0xD3 in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.ViewDidLoad C#
0x88 in UIKit.UIApplication.xamarin_UIApplicationMain C#
0x6 in UIKit.UIApplication.UIApplicationMain C#
0x51 in UIKit.UIApplication.Main C#
Steps to Reproduce
- Create a new Maui project
- Add an html asset file
data.html - Update view XAML to include
<WebView Source="data.html" /> - Verify working on windows/android
- Verify not working on iOS
Link to public reproduction project repository
https://github.com/Telavian/iosError
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 16
Did you find any workaround?
It appears using the current app directory works.
url = Path.Combine(Directory.GetCurrentDirectory(), url);
return $"file://{url}";
Relevant log output
No response
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
The issue will be fixed by https://github.com/dotnet/maui/pull/10804