1

I am trying to disable-web-security for WebView2 Runtime but there is no way to overload the EnsureCoreWebView2Async() function.

Any way we can add "--disable-web-security" to the webview2 runtime under WinUI3?

{
    CoreWebView2EnvironmentOptions environmentOptions = new CoreWebView2EnvironmentOptions() {
        AdditionalBrowserArguments = "--disable-web-security"
    };
    CoreWebView2Environment environment = await CoreWebView2Environment.CreateWithOptionsAsync("","", environmentOptions);
    await MyWebView.EnsureCoreWebView2Async(environment); #This shows error
    MyWebView.Source = new Uri(Path.Combine(Environment.CurrentDirectory, @"Html\mockup.html"));
    MyWebView.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;
}

Screenshot:

enter image description here

Ray
  • 1,539
  • 1
  • 14
  • 27

2 Answers2

2

You can set additional arguments by setting an environment variable before webview2 creation. Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--disable-web-security");

Niro
  • 314
  • 1
  • 4
  • 25
  • Does this support WinUI 3? – Dylech30th Dec 09 '21 at 23:28
  • My mistake, apparently you can't set disable-web-security through an environment variable. Other browser arguments are supported though (also in WinUI 3) – Niro Dec 12 '21 at 14:00
  • Thanks so much, I'm looking forward to finding a way to set the proxy ("--proxy-server") in webview2 for WinUI 3. I'll try this out – Dylech30th Dec 13 '21 at 14:07
1

There's currently no way to do this with WinUI3's WebView2 control.

The WinUI3 WebView2 control does not currently support initializing with a custom CoreWebView2Environment. The CoreWebView2Environment would be the only way to pass in a command line parameter like you are trying to do.

You may open a request to change this on the WinUI3 GitHub project.

David Risney
  • 3,886
  • 15
  • 16
  • Thank you for the answer, I checked the documentation also, there is no way to initialise in WinUI3 at the moment. – Ray Feb 05 '21 at 05:32