Describe the bug
Not sure if I have goofed something up in my setup or not... but I cannot seem to get WebView2 to load a file from the app package. Setting the UriSource to a web url local/remote works just fine.
But when trying to load an html file from the root of the project "/index.html" the screen stays blank and the NavigationCompleted event never fires.
Steps to reproduce the bug
Start a blank WinUI 3 project.
Install Microsoft.Web.WebView2 nuget package
Set controls namespace
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
Add WebView2 in XAML
Expected behavior
Expect the index.html file to be loaded.
Version Info
NuGet package version:
WinUI Version: 3.0.0-alpha.200210.0
WebView2 Version: 0.8.355
| Windows 10 version | Saw the problem? |
| :--------------------------------- | :-------------------- |
| Insider Build (xxxxx) | |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | YES |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) | |
| Device form factor | Saw the problem? |
| :-------------------- | :------------------- |
| Desktop | YES |
| Mobile | |
| Xbox | |
| Surface Hub | |
| IoT | |
@adambarlow @codendone does WebView2 support URIs into the app package ?
WebView2 _will_ support that, but ms-appx-web:/// and ms-appx-data:/// support is not yet implemented.
The internal task to implement this is https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/22121393.
Does webview2 support Uri's like ms-appx:///test.html or file:///C/temp/test.html or even ms-appx:///Assets/mypdf.pdf
I've not been able to load a local file using any variant of the above.
Using the latest version of WinUI 3.0 (preview 1) and Uwp.
@jabak I had alpha 1 working with file:///
for local resources (after resolving a ms-appx:///
url to a file:///
via the StorageFile
API) but with preview 1 I cannot get a local file to load via any means.
Great! Good to know that I'm not the only one seeing this behaviour in preview 1. I guess we'll have to wait for the next update then.
@codendone , which changes might have caused the local file loading to no longer function?
@adambarlow fyi I filed a full issue for that in MicrosoftEdge/WebViewFeedback here: https://github.com/MicrosoftEdge/WebViewFeedback/issues/212
@mqudsi Is this still not working for you? I see local files working fine in a Preview1 UWP with what sounds like the same approach you're using:
var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/SimplePage.html"));
this.webview.Source = new Uri(storageFile.Path);
@codendone You are right. Resolving the path as shown in your sample actually works. But loading local files by the following approach doesn't work:
this.webView.Source = new Uri("ms-appx:///Assets/SimplePage.html");
or
this.webView.Source = new Uri("file:///C:/temp/SimplePage.html");
or
this.webView.Source = new Uri("file:///C/temp/SimplePage.html");
or
this.webView.Source = new Uri("ms-appdata:///local/SimplePage.html");
or
this.webView.Source = new Uri("ms-appdata://local/SimplePage.html");
My impression was that if you can load a file in Edge/Chromium then WebView2 should be able to load the file as well.
@jabak Thanks for providing those explicit examples.
Supporting access to app files such as with ms-appx:/// is something we believe is required, and is something we're planning for. We could easily support this for just the WebView2.Source property, but expect that this type of protocol also needs to work from within the WebView2 (in the html/js), and therefore we are working towards that more complete solution. If having just WebView2.Source support would significantly help until we have the complete support, though, please let us know so we can consider adding this interim support.
but expect that this type of protocol also needs to work from within the
WebView2
Yep. Absolutely needed for us.
On Mon, 8 Jun 2020 at 18:34, Mike Crider notifications@github.com wrote:
@jabak https://github.com/jabak Thanks for providing those explicit
examples.
- ms-appx:// and ms-appdata:// are not supported at all yet. This is
being tracked both for WinUI3 (internal workitem
https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/22121415)
and for core Edge WebView2 (MicrosoftEdge/WebViewFeedback#37
https://github.com/MicrosoftEdge/WebViewFeedback/issues/37).- file:/// works, but only for files which the app has access to. UWP
applications have restricted file system access, which is largely just the
app package files and temp files. As a result, most files, including
anything in C:\temp, would not be accessible.Supporting access to app files such as with ms-appx:/// is something we
believe is required, and is something we're planning for. We could easily
support this for just the WebView2.Source property, but expect that this
type of protocol also needs to work from within the WebView2 (in the
html/js), and therefore we are working towards that more complete solution.
If having just WebView2.Source support would significantly help until we
have the complete support, though, please let us know so we can consider
adding this interim support.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/microsoft-ui-xaml/issues/1967#issuecomment-640738769,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AABDCD525VAESTRT7KFOJZDRVUHLDANCNFSM4KTI4IRQ
.
@codendone For me support for the source property would be adequate right now. But as I've only just started testing various things, including webview2, for my upcoming project I'm in no hurry. So I would say it's not significant to me. The more complete solution whenever that will be ready to ship gets my vote :o)
@phraemer Thanks for confirming. We'll keep that full support as required.
@jabak Thanks for your feedback!
Most helpful comment
WebView2 _will_ support that, but ms-appx-web:/// and ms-appx-data:/// support is not yet implemented.