0

I using CEFSharp WinForm to call website, but return blank page when using a Proxy server. If I turn off the proxy server setting, the website would be displayed. here is my code :

public ChromiumWebBrowser browser;

        public Form1()
        {
            try
            {
                InitializeComponent();

                InitBrowser();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString());
            }
        }


        public void InitBrowser()
        {
            try
            {
                CefSettings cfsettings = new CefSettings();
                //cfsettings.CefCommandLineArgs.Add("proxy-server", "200.29.191.149:3128");

                CefSharpSettings.ShutdownOnExit = true;
                //cfsettings.UserAgent = "My/Custom/User-Agent-AndStuff";
                // CefSharpSettings.Proxy = new ProxyOptions(ip: "213.166.75.178", port: "9275", username: "W09s1H", password: "eMwmFL");
                //cfsettings.DisableGpuAcceleration();
                Cef.Initialize(cfsettings);
                var rc1 = new RequestContext();
                browser = new ChromiumWebBrowser("https://whatismycountry.com/");
                panel1.Controls.Add(browser);
                browser.Dock = DockStyle.Fill;
                browser.IsBrowserInitializedChanged += Browser_IsBrowserInitializedChanged;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString());
            }
        }

        private void Browser_IsBrowserInitializedChanged(object sender, EventArgs e)
        {
            if (((ChromiumWebBrowser)sender).IsBrowserInitialized)
            {
                dd1();
                //if needed then use dev tool
                //browser.ShowDevTools();
            }
        }


        public async void dd1()
        {
            try
            {
                await SetProxy("91.188.241.26:9055");
                //await SetProxy("W09s1H:eMwmFL@91.188.241.26:9055");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString());
            }
        }
        public  Task SetProxy(string address)
        {
            try { 
            return Cef.UIThreadTaskFactory.StartNew(() =>
            {
                var context = browser.GetBrowser().GetHost().RequestContext;

                context.SetPreference("proxy", new Dictionary<string, object>
                {
                    ["mode"] = "fixed_servers",
                    ["server"] = address
                }, out _);
            });
        }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString());
                throw ex;
            }
}

and this is debug.log

[0201/073227.893:ERROR:gl_surface_egl.cc(668)] EGL Driver message (Critical) eglInitialize: No available renderers.
[0201/073227.893:ERROR:gl_surface_egl.cc(1115)] eglInitialize D3D11 failed with error EGL_NOT_INITIALIZED, trying next display type
[0201/073228.905:ERROR:gl_surface_egl.cc(668)] EGL Driver message (Critical) eglInitialize: No available renderers.
[0201/073228.905:ERROR:gl_surface_egl.cc(1115)] eglInitialize D3D9 failed with error EGL_NOT_INITIALIZED
[0201/073228.905:ERROR:gl_initializer_win.cc(196)] GLSurfaceEGL::InitializeOneOff failed.
[0201/073228.908:ERROR:viz_main_impl.cc(180)] Exiting GPU process due to errors during initialization
[0201/073228.933:WARNING:gpu_process_host.cc(1213)] The GPU process has crashed 1 time(s)
[0201/073229.084:WARNING:gpu_process_host.cc(982)] Reinitialized the GPU process after a crash. The reported initialization time was 28 ms
[0201/073229.095:ERROR:command_buffer_proxy_impl.cc(124)] ContextResult::kTransientFailure: Failed to send GpuChannelMsg_CreateCommandBuffer.
[0201/073229.095:WARNING:ipc_message_attachment_set.cc(49)] MessageAttachmentSet destroyed with unconsumed attachments: 0/1
[0201/073229.096:WARNING:ipc_message_attachment_set.cc(49)] MessageAttachmentSet destroyed with unconsumed attachments: 0/1

please help me ,how to use proxy and avoid this problem? i use windows 7 x86 and CEFSharp WinForm 79 Thanks fro help

Fath Bakri
  • 161
  • 1
  • 12
  • Does this answer your question? [c# cefsharp browser trying to set proxy](https://stackoverflow.com/questions/43483645/c-sharp-cefsharp-browser-trying-to-set-proxy) – AMA Feb 01 '20 at 17:21
  • Actually no, because i try what they said to put Configure() which contain definition of proxy before InitializeComponent() but still the same blank page?Any Help? – Fath Bakri Feb 01 '20 at 18:01
  • Any one have any idea to fix this problem? – Fath Bakri Feb 01 '20 at 19:02
  • Have you confirmed the proxy works in chrome? Does it require authentication? You are completely ignoring the result of SetPreference, you should check to see if it return an error http://cefsharp.github.io/api/79.1.x/html/M_CefSharp_IRequestContext_SetPreference.htm – amaitland Feb 01 '20 at 19:30
  • i have proxy username and password but at least it dose not ask for authentication, and i modify the code before and set out error but it show no error – Fath Bakri Feb 01 '20 at 20:02
  • You need to implement http://cefsharp.github.io/api/79.1.x/html/M_CefSharp_IRequestHandler_GetAuthCredentials.htm you can inherit from http://cefsharp.github.io/api/79.1.x/html/M_CefSharp_Handler_RequestHandler_GetAuthCredentials.htm and just override `GetAuthCredentials`, the `isProxy` param will be true. You have to implement your own dialog. – amaitland Feb 01 '20 at 22:04
  • https://stackoverflow.com/a/42376097/4583726 has a slightly outdated example, you can post an updated one to help others. – amaitland Feb 01 '20 at 22:06

0 Answers0