WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

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

Open GrandStrateguerre opened this issue 1 year ago • 4 comments

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 avatar Apr 30 '24 08:04 GrandStrateguerre

Hello, did you find something ?

GrandStrateguerre avatar Jun 01 '24 07:06 GrandStrateguerre

➕ I have same issue

Take-A-Byte avatar Sep 09 '24 11:09 Take-A-Byte

See issue 2381 and this comment: https://github.com/MicrosoftEdge/WebView2Feedback/issues/2381#issuecomment-3032253958 It might help.

omascia avatar Jul 05 '25 17:07 omascia

I am having the same issue. The only solution I found is to put a delay of 1 second between EnsureCoreWebView2Async and SetVirtualHostNameToFolderMapping

lregini-Insight avatar Oct 29 '25 21:10 lregini-Insight