MicrosoftEdge / WebView2Samples

Microsoft Edge WebView2 samples
830 stars 460 forks source link

"ERR_Blocked_by_client" Error in WebView on HoloLens 2 #227

Closed rgolomidov closed 5 months ago

rgolomidov commented 6 months ago

Hello, I am developing an application for HoloLens 2, integrating Unity 2021.3.32f1 with a UWP application. My application, which involves loading a PDF file in WebView2, works as expected when using Holographic Remoting but encounters an “ERR_Blocked_by_client” error when run directly on HoloLens 2 as a UWP application. This problem persists even with the standard "WebView2Samples" project, indicating a broader issue.

20231208_144139_HoloLens

michaelfarnsworth commented 6 months ago

@victorhuangwq if you are attempting to load the PDF from an arbitrary local on the device's file system, you just run into an error. As this could be a security issue. If you wish to load a PDF from the device, you should be able to leverage the SetVirtualHostMapping() method, mention here.

You'll just need to ensure that the PDF is deployed as an asset/resource with your APPX, with the correct relative path.

rgolomidov commented 6 months ago

Thank you, the error no longer appears, but now the application crashes every time. I will try to get this under control. The PDF file is on a server and is downloaded at runtime and stored in the ApplicationDataPath, from where it is then accessed via WebView.

rgolomidov commented 6 months ago

it work now! The SetVirtualHostMapping() is the way to go

LordKrampus commented 3 months ago

Some example of how that worked for me

((IWithVirtualHost)webView).SetVirtualHostMapping("webview2.sample", Application.dataPath + "/StreamingAssets/"); webViewComponent.Load(new Uri($"http://webview2.sample/{this.fileName}"));

Actually, if some trouble in path string, Unity crashes and shutdown (nothing about raising errors, exceptions, or Bug console for Unity).