首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过调用WebView2 mDNS来更改Microsoft行为?

如何通过调用WebView2 mDNS来更改Microsoft行为?
EN

Stack Overflow用户
提问于 2019-10-29 09:26:44
回答 3查看 2.1K关注 0票数 0

我正在使用Microsoft WebView2开发WebRTC应用程序。我希望将edge://flags/#enable-webrtc-hide-local-ips-with-mdns标志的值从“默认”更改为“禁用”。

根据MSDN https://learn.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference/webview2.idl,API CreateWebView2EnvironmentWithDetails有一个参数additionalBrowserArguments,它可以更改铬标志。我尝试过以下几个根本不起作用的值。

代码语言:javascript
运行
复制
WCHAR args[] = TEXT("--enable-webrtc-hide-local-ips-with-mdns=0");
WCHAR args[] = TEXT("--disable-webrtc-hide-local-ips-with-mdns");
WCHAR args[] = TEXT("--edge-webview-switches=\"--enable-webrtc-hide-local-ips-with-mdns=0\"");
WCHAR args[] = TEXT("--edge-webview-switches=--enable-webrtc-hide-local-ips-with-mdns=0");
WCHAR args[] = TEXT("--edge-webview-switches=--disable-webrtc-hide-local-ips-with-mdns");

上面的args不能在API中工作。

代码语言:javascript
运行
复制
CreateWebView2EnvironmentWithDetails(nullptr, nullptr, args, callback_handler);

我在窗口10上使用的是80.0.315.0 (正式构建)金丝雀(64位)版本的Microsoft。

提前感谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-11-21 05:44:26

根据MSDN https://learn.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference/webview2.idl,API CreateWebView2EnvironmentWithDetails有一个参数additionalBrowserArguments,它可以更改铬标志。我尝试过以下几个根本不起作用的值。

我已经和官方样品过程资源管理器试过了。这些论点被正确地添加到了过程中:

它不能工作的原因是因为没有这样的开关:

这是开关表运行带标志的铬找到的。我在列表中搜索,没有找到一个名为--enable-webrtc-hide-local-ips-with-mdns的开关。

当我通过edge://flags/#enable-webrtc-hide-local-ips-with-mdns手动启用标志并检查它时,开关如下所示:

所以答案很清楚,您应该将参数从--enable-webrtc-hide-local-ips-with-mdns更改为--enable-features=WebRtcHideLocalIpsWithMdns

票数 2
EN

Stack Overflow用户

发布于 2019-10-29 10:09:56

我在文档中找到了这个信息。

“除了启动浏览器进程的第一个WebView之外,不能保证应用这些开关。如果指定的交换机解析失败,它们将被忽略。nullptr将运行没有标志的浏览器进程。”

参考资料:

成员

您还可以尝试从Edge (铬)浏览器中提供有关此问题的反馈。

票数 1
EN

Stack Overflow用户

发布于 2022-06-17 08:56:45

此代码演示如何在匿名代理中使用WebView2并防止WebRTC泄漏。

消除WebRTC泄漏的最简单方法是在应用程序第一次启动时更改注册表中的策略。这可以在LocalMachine或CurrentUser级别完成。CurrentUser是最好的。https://admx.help/?Category=EdgeChromium&Policy=Microsoft.Policies.Edge::WebRtcLocalhostIpHandling

将WebRtcLocalhostIpHandling注册表项设置为disable_non_proxied_udp将防止IP泄漏。

代码语言:javascript
运行
复制
Dim RegKey = My.Computer.Registry.CurrentUser.CreateSubKey("Software\Policies\Microsoft\Edge\WebView2")
RegKey.SetValue("WebRtcLocalhostIpHandling", "disable_non_proxied_udp", Microsoft.Win32.RegistryValueKind.String)

我在窗体上运行下面的代码来清理

代码语言:javascript
运行
复制
Dim RegKey = My.Computer.Registry.CurrentUser.CreateSubKey("Software\Policies\Microsoft\Edge")
If RegKey.GetSubKeyNames.Contains("WebView2") Then RegKey.DeleteSubKey("WebView2")

相同的代码完全适用于Edge:

代码语言:javascript
运行
复制
Dim RegKey = My.Computer.Registry.CurrentUser.CreateSubKey("Software\Policies\Microsoft\Edge")
RegKey.SetValue("WebRtcLocalhostIpHandling", "disable_non_proxied_udp", Microsoft.Win32.RegistryValueKind.String)

我在窗体上运行下面的代码来清理

代码语言:javascript
运行
复制
Dim RegKey = My.Computer.Registry.CurrentUser.CreateSubKey("Software\Policies\Microsoft\Edge")
If RegKey.GetValueNames.Contains("WebRtcLocalhostIpHandling") Then RegKey.DeleteValue("WebRtcLocalhostIpHandling")

您还可以使用下面的代码来防止LocalIP泄漏(现在默认情况下应该阻止这种泄漏),并强制WebView2流量通过您选择的代理服务器。

代码语言:javascript
运行
复制
Dim TargetURL As String = "https://proxy6.net/en/privacy"
Dim Proxy As String = "1.1.1.1:8080"
Dim WV As Microsoft.Web.WebView2.WinForms.WebView2 = New Microsoft.Web.WebView2.WinForms.WebView2
WV.Dock = DockStyle.Fill
Form1.Controls.Add(WV)
AddHandler WV.NavigationCompleted, AddressOf WV_NavigationCompleted
Dim Options As CoreWebView2EnvironmentOptions = New CoreWebView2EnvironmentOptions()
' Force the traffic through a proxy server?
If Proxy <> "" Then Options.AdditionalBrowserArguments = "--proxy-server=" & Proxy
' Prevent WebRTC leaks of local IP addresses 
Options.AdditionalBrowserArguments &= " --enable-features=WebRtcHideLocalIpsWithMdns"
Dim env As CoreWebView2Environment = Await CoreWebView2Environment.CreateAsync(Nothing, Nothing, Options)
Await WV.EnsureCoreWebView2Async(env)
' Any javascript we want to inject / run for every page?
Await WV.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("//Javascript to add / run each time a page is created ")
WV.Source = New Uri(TargetURL, UriKind.Absolute)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58604537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档