MicrosoftEdge / WebView2Feedback

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

img tag source loading - stuck in pending network status #1175

Open Skarnivorous opened 3 years ago

Skarnivorous commented 3 years ago

For reference - for a local folder index.html source in the webview2 control. The img sources were coded something like:

<img src="../user/items/image1.png"/>

The network requests for img source would sit in 'Pending' for a long time, and then all calls for resources after about 10-20 seconds would load fine.

The resolution was to immediately map a virtual host name to the local folder after EnsureCoreWebView2Async and use proper address source.

await AppWebView.EnsureCoreWebView2Async(null);
AppWebView.CoreWebView2.SetVirtualHostNameToFolderMapping("SLG.user", slg.appPath + "user/items/", CoreWebView2HostResourceAccessKind.DenyCors);
<img src="https://SLG.user/image1.png"/>

The pending network status no longer occurs and images load immediately. I assume some initial handshake/connection for the control to the actual local folder path was taking some time. Whether this is a bug or not, I can't be sure - it is likely better practice to set up the virtual host name anyway.

AB#32524620

champnic commented 3 years ago

Hey @Skarnivorous - being blocked on local resource access for 10-20 sounds suspiciously like an antivirus is running a scan or something similar. I'll change this to a bug on our backlog and we'll see if we can reproduce the behavior with local content. I'm glad you have a workaround though :)

Skarnivorous commented 3 years ago

Thanks - I am quite happy with the performance/response after mapping the virtual host name - but it is a little 'unexplained' behaviour so I just wanted to have it logged here and how I worked around it for anyone else to reference if they find similar situation.