Qter 发表于 2021-9-6 15:47:57

chrome设置代理

本帖最后由 Qter 于 2022-3-10 15:16 编辑

https://www.linuxdashen.com/%E5% ... E%E4%BB%A3%E7%90%86QCefViewBrowserApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)command_line->AppendSwitchWithValue("--default-background-color", "ff000000");//使用背景颜色
command_line->AppendSwitchWithValue("--background-color", "black");//使用背景颜色
command_line->AppendSwitch("--off-screen-rendering-enabled");
command_line->AppendSwitch("--transparent-painting-enabled");


command_line->AppendSwitchWithValue("proxy-server", "socks5://127.0.0.1:8888");


https://cpp.hotexamples.com/exam ... ethod-examples.html


https://magpcss.org/ceforum/apidocs3/projects/(default)/CefCommandLine.html    CefCommandLine::SwitchMap switches;command_line->GetSwitches(switches);

"You should use AppendSwitchWithValue("proxy-server", "socks5://127.0.0.1:8888")"

Qter 发表于 2021-9-24 15:52:34

本帖最后由 Qter 于 2021-9-24 15:54 编辑

相关源码

https://www.magpcss.org/ceforum/viewtopic.php?t=17346

https://chromium.googlesource.co ... content_switches.cc
https://bitbucket.org/chromiumembedded/cef/issues?status=new&status=open

Qter 发表于 2022-3-7 20:01:38

在集成cef3时,遇到一个设置代理的问题,cef3提供了两个设置代理的方式

继承CefApp类,通过实现接口OnBeforeCommandLineProcessing回调设置,
OnBeforeCommandLineProcessing回调中包含CefCommandLine命令行控制实例,调用CefCommandLine实例的AppendSwitchWithValue方法设置相关属性开关,如设置代理command_line->AppendSwitchWithValue("--proxy-server", "192.168.1.100:8000");,调用AppendSwitch方法设置不需要值的属性开关,如取消代理设置command_line->AppendSwitch("--no-proxy-server");
此方法设置的代理为全局属性,且初始化(CefInitialize)后该回调只会触发一次

继承CefRequestHandler类,通过实现接口OnBeforeBrowse回调设置,通过OnBeforeBrowse回调中的CefBrowser实例获取CefBrowserHost实例,再通过CefBrowserHost实例获取CefRequestContext实例,调用CefRequestContext实例的SetPreference方法设置属性值,设置代理方法如下:

CefRefPtr<CefDictionaryValue> dict = CefDictionaryValue::Create();
dict->SetString("mode", "fixed_servers");
dict->SetString("server", "192.168.1.100:8000");

CefRefPtr<CefValue> value = CefValue::Create();
value->SetDictionary(dict);
context->SetPreference("proxy", value, error);
1
2
3
4
5
6
7
如需取消代理设置,只需将SetPreference方法的第二个参数设为NULL,即:

context->SetPreference("proxy", NULL, error);
1
此方法设置的代理针对单独的CefBrowser实例,且每次加载完成都可以重新设置
————————————————
版权声明:本文为CSDN博主「SarznLiu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liusarzn/article/details/109051551


https://blog.csdn.net/liusarzn/article/details/109051551?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-2-109051551.pc_agg_new_rank&utm_term=CEF+%E4%BB%A3%E7%90%86%E8%AE%BE%E7%BD%AE&spm=1000.2123.3001.4430


Qter 发表于 2022-3-7 20:35:02

chromium --proxy-server="socks5://127.0.0.1:1080"
Chromium和Chrome支持HTTP,HTTPS,SOCKS4和SOCK5代理。配置HTTPS代理:

chromium --proxy-server="https://proxy-ip:proxy-port"

Qter 发表于 2022-3-7 22:12:32

//command_line->AppendSwitch("no-proxy-server");
command_line->AppendSwitchWithValue("--proxy-server", "127.0.0.1:19181");
command_line->AppendSwitchWithValue("--proxy-server", "http://127.0.0.1:19181");
command_line->AppendSwitchWithValue("--proxy-server", "https://127.0.0.1:19181");
command_line->AppendSwitchWithValue("--proxy-server", "socks5://127.0.0.1:19181");
command_line->AppendSwitchWithValue("proxy-server", "SOCKS5://127.0.0.1:19181");

Qter 发表于 2022-3-8 11:35:29

cache_path = QString(QDir::current().path() + "/" + CACHE_DIRECTORY_NAME).toStdString();
//需要用浏览器调试再放开下面这行代码
remote_debugging_port = QCEF_REMOTE_DEBUGGING_PORT;

页: [1]
查看完整版本: chrome设置代理