MicrosoftEdge / WebView2Feedback

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

CoreWebView2Settings Can Add WebSecurity Property? #1217

Closed TidyScript closed 3 years ago

TidyScript commented 3 years ago

如题。 由于总是遇到同源策略的阻止问题,所以想关掉WebSecurity选项。

参考对象:CefSharp: browser.BrowserSettings.WebSecurity = CefState.Disabled;

TidyScript commented 3 years ago

等同于下面的代码: var op = new CoreWebView2EnvironmentOptions("--disable-web-security"); var env = await CoreWebView2Environment.CreateAsync(null, null, op); await edge.EnsureCoreWebView2Async(env);

champnic commented 3 years ago

If I understand correctly you found a workaround for this issue. Disabling web security is not something we want to encourage and so won't expose this in a simpler API. Thanks!

ilovepumpkin commented 2 years ago

We have same requirement, and we are using WinUi3, but unfortunately there is no env parameter in EnsureCoreWebView2Async signature. https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.controls.webview2.ensurecorewebview2async?view=winui-3.0

champnic commented 2 years ago

Hey @ilovepumpkin - for WinUI 3 and WinUI 2 controls, you should be able to use the WEBVIEW2_ADDITIONAL_BROWSER_ARGS environment variable to set the browser args before initializing the WebView2. You can set that variable from within your app. Thanks!