You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
I'm trying to use SetVirtualHostNameToFolderMapping to map a host name to a local folder, from within a WebMessageReceived event handler. If I then create an image within the webview with an src referencing the mapped hostname, the mapping is ignored, and DevTools console displays: Failed to load resource: net::ERR_NAME_NOT_RESOLVED.
Version
SDK: 1.0.1248-prerelease
Runtime: 101.0.1210.39 (Official build) (64-bit)
Framework: WPF
OS: Windows 10 Home 21H2 (build 19044.1706)
Repro Steps
Call postMessage from JavaScript within the webview.
In the handler WebMessageReceived, call SetVirtualHostNameToFolderMapping
In the mesage event listener, set the src of an image to something in the mapped host folder.
@champnic I know that setting the mapping before navigation works; and reloading would also probably work. But the virtual host target path may change multiple times over the lifetime of the application, and I don't really want to reload each time.
But instead of removing and recreating the virtual host path, I can create (and recreate) a symbolic link to the target path as needed. Then, at application start, I can map the virtual host to the symbolic link:
varsymlinkPath=
Path.Combine(
Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location!)!,"assets");// In order to map the virtual host name, the directory has to exist// Creating a dummy folder here
Directory.CreateDirectory(symlinkPath);
webview.CoreWebView2.SetVirtualHostNameToFolderMapping("assets",
symlinkPath,
CoreWebView2HostResourceAccessKind.Allow
);
webview.CoreWebView2.WebMessageReceived +=(s,e)=>{ Directory.Delete(symlinkPath); Directory.CreateSymbolicLink(symlinkPath,@"C:\Users\Spitz\Desktop\testmd"); webview.CoreWebView2.PostWebMessageAsString(@"breakpoint.bmp");};
Description
I'm trying to use SetVirtualHostNameToFolderMapping to map a host name to a local folder, from within a WebMessageReceived event handler. If I then create an image within the webview with an
src
referencing the mapped hostname, the mapping is ignored, and DevTools console displays: Failed to load resource: net::ERR_NAME_NOT_RESOLVED.Version
SDK: 1.0.1248-prerelease
Runtime: 101.0.1210.39 (Official build) (64-bit)
Framework: WPF
OS: Windows 10 Home 21H2 (build 19044.1706)
Repro Steps
mesage
event listener, set the src of an image to something in the mapped host folder.Additional context
Project illustrating the problem: _testWebviewDialogs.zip
SO question
XAML:
Code behind:
container.html
:The text was updated successfully, but these errors were encountered: