maui
maui copied to clipboard
`LoadFile` in `src/Core/src/Platform/iOS/MauiWKWebView.cs` ignore directories.
Description
In macOS (net8.0-maccatalyst), I wrote the following code in order to open Resources/Raw/foo/bar.html in WebView.
WebView.Source = new UrlWebViewSource {
Url="foo/bar.html",.
};
The directory name foo/ is ignored and bar.html is tried to be read.
I checked the implementation and found that the directory name is ignored in the following places.
https://github.com/dotnet/maui/blob/45a86865ffc44a501b1c4c8d6b50ee419d1696b9/src/Core/src/Platform/iOS/MauiWKWebView.cs#L176-L183
LoadFile is called from LoadUrlAsync because foo/bar.html is a invalid format URI.
https://github.com/dotnet/maui/blob/45a86865ffc44a501b1c4c8d6b50ee419d1696b9/src/Core/src/Platform/iOS/MauiWKWebView.cs#L120-L134
It was possible to open the file from Resources/Raw/index.html with a reference to <a href="foo/bar.html" >foo/bar</a>".
It was also possible to open the file by getting the full path from OpenAppPackageFileAsync as described in the workaround.
Sorry if this is a limiting issue for other platforms such as iOS, however in that case it would be kind if it is commented in the documentation or source code.
Thanks.
Steps to Reproduce
- Create a file
Resources/Raw/foo/bar.html. - Create a Page with
<WebView Source="foo/bar.html" />element.
Link to public reproduction project repository
No response
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
macOS Sonoma 14.5
Did you find any workaround?
private async Task InitializeWebView()
{
using var stream = await FileSystem.OpenAppPackageFileAsync("foo/bar.html");
if (stream is FileStream f)
{
WebView.Source = new UrlWebViewSource {
Url=f.Name,
};
}
}
Relevant log output
No response
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Open similar issues:
- Webview on iOS and Android does not allow local HTML to load additional resources (#20613), similarity score: 0.71
Closed similar issues:
- Maui iOS failing to load local resources in using WebView Source (#10674), similarity score: 0.77
- .NET MAUI project using the PDF.js library - Issue loading the PDF from iOS resource (#19486), similarity score: 0.72
- Can't use WebView with local files stored as MauiAssets on Windows (#16646), similarity score: 0.71
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Hi @kxc-wraikny. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I have added link to the reproduction repo.
I can repro this issue on the latest Visual Studio 17.6.12(build410) (8.0.61 & 8.0.21)