CefGlue CefRequestContext set proxy

473 views
Skip to first unread message

laserma...@gmail.com

unread,
Nov 7, 2016, 10:54:56 AM11/7/16
to CefGlue
Guys , is there ability to change Proxy for requestContext ?

I've found on Internet few posts regarding this , but Related to CefSharp implementation.

 var v = new Dictionary<string, object>();
 v["mode"] = "fixed_servers";
 v["server"] = Proxy;
 string error;
 bool success = rc.SetPreference("proxy", v, out error);

I've tried to do the same for CefGlue requestContext , but with no luck , SetPreference out error parameter returns Empty.
But there is no effect on proxy settings.

Also I've tried to call 

requestContext.GetAllPreferences(true);

to see , how the preferences are structured , but it returns NullReferenceExeption.

I am trying to do it on new created requestContext

 var requestContext = CefRequestContext.CreateContext(requestContextSettings, contextHandler);

Maybe I am missing some initialization ?
Or maybe I am setting the Value wrong ? 

I've tried like this : 
string err;
                            CefDictionaryValue proxyDic = CefDictionaryValue.Create();
                            proxyDic.SetString("proxy", "http://x.x.x.x:57781");
                            var v = CefValue.Create();
                            v.SetDictionary(proxyDic);
                            requestContext.SetPreference("proxy", v, out err);
                            var proxy = requestContext.GetPreference("proxy");





Dmitry Azaraev

unread,
Nov 7, 2016, 11:04:49 AM11/7/16
to CefGlue
Hello.

First you should call it on CEF UI thread if not already.

Second, - getting preferences may be not helpful, because there is not exists (they are in default state, i'm doesn't remember if they returned). Also you can use cefclient to play around preferences (look in tests menu, or tests -> others).

I'm setting proxy in next way:

                    using (var value = CefValue.Create())
                    using (var items = CefDictionaryValue.Create())
                    {
                        value.SetDictionary(items);

                        // Fixed-Servers proxy
                        items.SetString("mode", "fixed_servers");
                        items.SetString("server", <proxy_server_string_here>);

                        // No-Proxy mode
                        // items.SetString("mode", "direct");

                        string error;
                        if (!cefRequestContext.SetPreference("proxy", value, out error))
                        {
                            throw new InvalidOperationException($"SetPreference: {error}");
                        }
                    }

Again, try cefclient to get brief about preferences, and get different options for proxy.



--
You received this message because you are subscribed to the Google Groups "CefGlue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefglue+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dmitry Azaraev

unread,
Nov 7, 2016, 11:08:05 AM11/7/16
to CefGlue
For fixed servers mode proxy string in ip_address:port format, no protocol prefixes.

laserma...@gmail.com

unread,
Nov 7, 2016, 12:09:11 PM11/7/16
to CefGlue, dmitry....@gmail.com
Dmitry your code is worked perfectly. The CefUi thread was the problem.
I need to read more about CEF first , before starting to play with CefGlue code.

Anyway thank you very much !!!!

Dmitry Azaraev

unread,
Nov 7, 2016, 12:12:46 PM11/7/16
to CefGlue
Yep, main goal of CefGlue is provide unrestricted/similar CEF API as much as possible. Read CEF usage wiki, it contains many stuff. Also don't ignore CEF documentation headers (all of them moved as xmldoc comments, but sometimes it is easier just read original include files (they more short)).
Reply all
Reply to author
Forward
0 new messages