Switch proxy dynamically using Chromiumfx

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.

Switch proxy dynamically using Chromiumfx

Postby raj3690 » Mon Feb 22, 2021 9:26 am

Hello Everyone,

Could anyone help me on how to change the proxy settings dynamically in cef using Chromiumfx wrapper?
I able to change the proxy settings using commandline arguments at the time of initialization which is not useful for my current case.

I tried to change the preferences in the RequestContext like below.

Code: Select all
var browser = new ChromiumWebBrowser();
            var cfxRequestContext = browser.BrowserHost.RequestContext;

            var cfxProxyValue = CfxValue.Create();
            var cfxMode = CfxValue.Create();
            var cfxServer = CfxValue.Create();
            var cfxDictionaryValue = CfxDictionaryValue.Create();

            cfxServer.SetString("URL:PORT");
            cfxDictionaryValue.SetValue("mode", cfxMode);
            cfxDictionaryValue.SetValue("server", cfxServer);
            cfxProxyValue.SetDictionary(cfxDictionaryValue);
         //Calling this on the UI thread
            browser.InvokeOnUiThread(() =>
            {
               cfxRequestContext.SetPreference("proxy", cfxProxyValue, out var errorOut);
            });


It is not setting the values and not throwing any error; errorOut value coming null.
Referring to the link,https://bitbucket.org/chromiumembedded/cef/issues/1709/allow-configuration-of-preferences-during, I understand that proxy settings can be changed during runtime in cef, but couldn't able to find how to a do it using chromiumfx.
I have tried it similar to viewtopic.php?f=6&t=15724 but no luck.

Any help would be greatly appreciated.

Thanks,
Raj.
raj3690
Newbie
 
Posts: 2
Joined: Thu Dec 10, 2020 4:56 am

Re: Switch proxy dynamically using Chromiumfx

Postby amaitland » Wed Feb 24, 2021 11:08 pm

SetPreference can only be called on the CEF UI thread, are you sure InvokeOnUiThread executes on the CEF UI thread?

What does errorOut say?

Try calling SetPreference in a handler method that's already called on the CEF UI thread like OnAfterCreated.

Is Chromiumfx still actively being developed? Last I checked the project site was deleted. I'd be switching to a different browser.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1291
Joined: Wed Jan 14, 2015 2:35 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 58 guests