c++ - WebView2 代理 C++
问题描述
我在 GitHub 上找到了这个线程,但似乎代码不是 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
课。
解决方案
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());
而不是SERVER
放ip地址或其他东西。
我测试过,它可以工作,但似乎有一个错误(或功能):你不能创建两个或多个具有不同运行参数的 webview。
推荐阅读
- laravel - 如何发送多封电子邮件以获取视图中的用户数据 - Laravel
- .net - 在 .NET 应用程序和 UWP 应用程序之间传递消息
- json - 是否可以在没有模板消息的情况下使用 NLog 的结构化日志记录?
- javascript - 如何使用 do while 循环多次将字符串推送到数组中?
- python - 通过 URL 从 excel 下载 Web 图像并保存到 Python 中的文件夹
- python - 按日期范围对数据框进行子集
- wordpress - Woocommerce 动作挂钩未触发
- stm32 - STM32F446RE 引导加载程序如何工作?
- dotnetnuke - 在 DotNetNuke-7 模块中查看服务器端代码
- apache-spark - 从包含实际文件路径的文本文件生成 rdd