MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
423 stars 51 forks source link

[Problem/Bug]: With CoreWebView2.SetVirtualHostNameToFolderMapping shows error Ip adress when start a local site #4516

Open GrandStrateguerre opened 2 months ago

GrandStrateguerre commented 2 months ago

What happened?

Hi, I use this configuration :

CoreWebView2.SetVirtualHostNameToFolderMapping(hostName, hostFolderPath, CoreWebView2HostResourceAccessKind.Allow);
//Where hostName = "ThreeJS", hostFolderPath="D:\WebView\ThreeJS"

to start a local site.

For starting the site , I use :

       private void _WebView_CoreWebView2InitializationCompleted(object? sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
       {
           // Navigate to the index.html page
           _WebView.Source = new Uri("http://ThreeJS/index.html");
       }

Here is the index.html :

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>My first three.js app</title>
        <style>
            body { margin: 0; }
        </style>
    </head>
    <body>
        <script type="module" src="/main.js"></script>
    </body>
</html>

And when I run the code, I get : image

Then after several seconds, I get the site : image

Here is below a video :

https://github.com/MicrosoftEdge/WebView2Feedback/assets/86523070/004ee143-41d9-4e0a-aa58-38e19d4a2f01

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

124.0.2478.67

SDK Version

1.0.2478.35

Framework

WPF

Operating System

Windows 10

OS Version

Version : 22H2, Build : 19045.4291

Repro steps

Configure the WebView2 WPF for hosting in folder with :

 CoreWebView2.SetVirtualHostNameToFolderMapping(hostName, hostFolderPath, CoreWebView2HostResourceAccessKind.Allow);

Where hostName = "ThreeJS", hostFolderPath="D:\WebView\ThreeJS"

 private void _WebView_CoreWebView2InitializationCompleted(object? sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
       {
           // Navigate to the index.html page
           _WebView.Source = new Uri("http://ThreeJS/index.html");
       }

Here is the index.html (to put in D:\WebView\ThreeJS folder) :

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>My first three.js app</title>
        <style>
            body { margin: 0; }
        </style>
    </head>
    <body>
        <!-- <script type="module" src="/main.js"></script> -->
    </body>
</html>

Then you will see first the message about the Ip adresse.

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

GrandStrateguerre commented 1 month ago

Hello, did you find something ?