Change proxy at run time

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Change proxy at run time

Postby GoodGuySoft » Wed Oct 05, 2016 8:39 am

I read a lot about CEF3, but I still don't see how to change proxy at runtime? So, I started application, opened some web page in browser with `proxy1`; I want to change proxy to `proxy2` now with C++ code and open next page with this new proxy from my program. How to do that? Chrome and any other browser does it easily. So, I need something similar to InternetSetOption(NULL, INTERNET_OPTION_PROXY, intptrStruct, sizeof(struct_IPI)); For sure, I don't want to change system global proxy just because of my embedded web browser. Also even if I change them, will CEF3 update its settings "one the fly"? Or may be I can somehow restart background process?
GoodGuySoft
Newbie
 
Posts: 9
Joined: Fri Sep 30, 2016 7:19 am

Re: Change proxy at run time

Postby magreenblatt » Wed Oct 05, 2016 1:16 pm

Proxy settings can be changed at runtime using CefRequestContext::SetPreference. See the Tests > Other tests > Preferences example in cefclient (cefclient/browser/preferences_test.cc).
magreenblatt
Site Admin
 
Posts: 12404
Joined: Fri May 29, 2009 6:57 pm

Re: Change proxy at run time

Postby GoodGuySoft » Thu Oct 06, 2016 4:09 am

Yep, that's work, thanks. I post code here, so may be it will help other people to not search in source:

Code: Select all
// Set proxy
auto hostProcess = browser->GetHost();
auto requestContext = hostProcess->GetRequestContext();
CefString error;
auto proxyDictionary = CefDictionaryValue::Create();
proxyDictionary->SetString(L"mode", L"fixed_servers");
proxyDictionary->SetString(L"server", L"http://127.0.0.1:8080");
auto proxyValue = CefValue::Create();
proxyValue->SetDictionary(proxyDictionary);
if (!requestContext->SetPreference(L"proxy", proxyValue, error))
   wprintf(L"Can not set proxy. %ls\r\n", error.c_str());
GoodGuySoft
Newbie
 
Posts: 9
Joined: Fri Sep 30, 2016 7:19 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 37 guests

cron