2

I am using the following code for the proxy. however, when chrome starts, pop-up window will pop up and the program will be locked.

public async void StartDriver(string proxy) { var proxys = new Proxy(); ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(); chromeDriverService.HideCommandPromptWindow = true; ChromeOptions chromeOptions = new ChromeOptions(); bool flag = !string.IsNullOrEmpty(proxy); if (flag) { proxys.Kind = ProxyKind.Manual; proxys.IsAutoDetect = false; proxys.SslProxy = proxy; chromeOptions.Proxy = proxys; } driver = new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromMinutes(10)); await Task.Delay(2000); } 

I tried http or ssl the same...

StartDriver("88.55.66.77:8080"); 

Or

StartDriver("http://username:[email protected]:8080"); 

I could not start a browser with a kind of proxy.

I want a code that automatically enters the username and password. I don't want autoitx3.dll.

is there a way to start a secure proxy?

Thank you.

    3 Answers 3

    5

    In 2021 you can use Selenium 4.0 and BiDi APIs for making requests through a proxy with authorization. Example:

    var options = new ChromeOptions {AcceptInsecureCertificates = true}; options.AddArgument("headless"); options.Proxy = new Proxy {HttpProxy = "1.1.1.1:12345", SslProxy = "1.1.1.1:12345", Kind = ProxyKind.Manual}; //options.AddArguments($"--proxy-server=http://1.1.1.1:12345"); var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(2)); NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler() { UriMatcher = d => true, //d.Host.Contains("your-host.com") Credentials = new PasswordCredentials("proxy_user", "proxy_pass") }; var networkInterceptor = driver.Manage().Network; networkInterceptor.AddAuthenticationHandler(handler); networkInterceptor.StartMonitoring(); _driver.Navigate().GoToUrl("https://stackoverflow.com/"); networkInterceptor.StopMonitoring(); driver.Quit(); 
    1
    • 1
      Thanks! it finally work!CommentedMar 9, 2022 at 14:55
    2

    is there a way to start a secure proxy?

    There's one. You need to create a chrome extension with proxy settings.

    manifest.json

     { "version": "0.1.0", "manifest_version": 2, "name": "%NAME IT AS YOU WANT%", "permissions": [ "proxy", "tabs", "unlimitedStorage", "storage", "<all_urls>", "webRequest", "webRequestBlocking" ], "background": { "scripts": ["background.js"] }, "minimum_chrome_version":"22.0.0" } 

    background.js

    //note that it's a JS code. You can use any additional code to do anything :) var config = { mode: "fixed_servers", rules: { singleProxy: { scheme: "http", host: "%HOST%", port: parseInt(%PORT%) }, bypassList: ["foobar.com"] } }; chrome.proxy.settings.set({value: config, scope: "regular"}, function() {}); function callbackFn(details) { return { authCredentials: { username: "%USERNAME%", password: "%PASSWORD%" } }; } chrome.webRequest.onAuthRequired.addListener( callbackFn, {urls: ["<all_urls>"]}, ['blocking'] ); 

    Pack it as an archive. For instance yourExt.dat

    var proxy = "yourExt.dat"; var options = new ChromeOptions(); options.AddExtension(proxy); var driver = new ChromeDriver(options); 
    1
    • This answer is correct but the final part is quite confusing. The packed file is not .dat extension else is just creating a .crx file that you can generate within any Chrome with the above files and options.AddExtension(proxy); only load extensions file in .crx format.CommentedJan 1, 2020 at 11:42
    0

    Selenium 4 has a bug. WebSocket exception during performing basic authorization https://github.com/SeleniumHQ/selenium/issues/10054

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.