Skip to content

Set Proxy Per Browser #1813

Closed
Closed

Description

@AgapovAlexsey

Hi. How i can use different proxy for different instances class ChromiumWebBrowser?
I set proxy as shown below:

 Cef.UIThreadTaskFactory.StartNew(delegate {
      var rc = chromeBrowser.GetBrowser().GetHost().RequestContext;
      var v = new Dictionary<string, object>();
      v["mode"] = "fixed_servers";
      v["server"] = "socks5://127.0.0.1:9190";
      string error;
      bool success = rc.SetPreference("proxy", v, out error);                
    });      

But it changed proxy for all instances ChromiumWebBrowser.

Activity

  1. amaitland commented on Sep 24, 2016

    @amaitland
    Member

    Search on Gitter, topic has been covered a few times. Next time please take the time to read the issue template.

  2. amaitland commented on Sep 25, 2016

    @amaitland
    Member

    For reference here is an updated example in the context of WPF for SetPreference on a newly created RequestContext, same concept applies for WinForms, just create and assign your RequestContext then set your preferences on the CEF UI thread.

    b3a2369#diff-670f0330cbeb12f911a2f6f4af481dc2L44

    More info related to setting proxies is at http://stackoverflow.com/questions/36095566/cefsharp-3-set-proxy-at-runtime

    If you set the proxy settings through Cef.Initialize, aka command line argument, you won't be able to change them using SetPreference, they'll be fixed. You have to only set them through SetPreference

    Additional note for anyone else.

  3. changed the title [-]different proxy[/-] [+]Set Proxy Per Browser[/+] on Sep 25, 2016
  4. DianaArquillos commented on Feb 16, 2018

    @DianaArquillos
  5. 28141932 commented on Sep 7, 2018

    @28141932
  6. ToxaDev commented on Jan 3, 2020

    @ToxaDev
  7. amaitland commented on Jan 3, 2020

    @amaitland
    Member

    The browser provides an initialized event, the WinForms/WPF/OffScreen implementation slightly differs, the relevant docs are.

    http://cefsharp.github.io/api/75.1.x/html/E_CefSharp_Wpf_ChromiumWebBrowser_IsBrowserInitializedChanged.htm
    http://cefsharp.github.io/api/75.1.x/html/E_CefSharp_OffScreen_ChromiumWebBrowser_BrowserInitialized.htm
    http://cefsharp.github.io/api/75.1.x/html/E_CefSharp_WinForms_ChromiumWebBrowser_IsBrowserInitializedChanged.htm

    If you have multiple browsers that share the RequestContext then using http://cefsharp.github.io/api/75.1.x/html/M_CefSharp_IRequestContextHandler_OnRequestContextInitialized.htm is the option I'd recommend. See https://github.com/cefsharp/CefSharp/blob/cefsharp/75/CefSharp.Wpf.Example/Handlers/RequestContextHandler.cs#L24 for an example.

    You will have to create a new RequestContext instance to use this method.

    SetPreference must be called on the UI thread and only after the RequestContext has been initialized. The browser initialized events are guaranteed to be called after the RequestContext has been initialized.

    If you set the proxy via the command line then you will be unable to modify it using SetPreference.

    Further questions please use one of the support options listed at https://github.com/cefsharp/CefSharp#contact

  8. locked as resolved and limited conversation to collaborators on Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions