我在GitHub上找到了this线程,但代码似乎不是C++:
WebView2 _webView2 = new WebView2();
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions();
// Set a proxy pac for the browser
// options.AdditionalBrowserArguments = "--proxy-pac-url=http://myproxy.com/my.pac";
// Set the proxy for the browser
options.AdditionalBrowserArguments = "--proxy-server=\"foopy:99\"";
// Create the environment manually
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(null, null, options);
await _webView2 .EnsureCoreWebView2Async(env);因此,我唯一要求的是提供通过C++为WebView2设置代理的解决方案。
我有ICoreWebView2接口,但它没有EnsureCoreWebView2Async方法。另一方面,我有CoreWebView2EnvironmentOptions类。
发布于 2020-12-31 00:51:48
auto opt = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
opt->put_AdditionalBrowserArguments(L"--proxy-server=\"SERVER\"");
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, opt.Get(), Microsoft::WRL::Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
[hwnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
...
}).Get());输入ip地址或其他地址,而不是SERVER。
我测试过,它工作了,但似乎有一个bug (或功能):你不能创建两个或更多的webviews与不同的运行参数。
https://stackoverflow.com/questions/65481185
复制相似问题