SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.72k stars 8.01k forks source link

[🐛 Bug]: Socks5 Proxy (Chrome) #13820

Open TurboKoT1 opened 2 months ago

TurboKoT1 commented 2 months ago

What happened?

When I connect to a socks5 proxy - I completely lose internet in my browser. The proxy is fully working.

Code: ` ChromeOptions options = new ChromeOptions();

    Proxy proxy = new Proxy();
    proxy.setProxyType(Proxy.ProxyType.MANUAL);
    proxy.setAutodetect(false);

    proxy.setSocksProxy("123.456.789.123:1234");
    proxy.setSocksUsername("username");
    proxy.setSocksPassword("password");
    proxy.setSocksVersion(5);

    options.setCapability("proxy", proxy);

    WebDriver driver = new ChromeDriver(options);
    driver.manage().window().maximize();

    driver.get("http://2ip.io");`

Before that, I tried to use the flags of the browser itself, which also didn't give any result: ` ChromeOptions options = new ChromeOptions();

    options.addArguments("--proxy-server=socks5://123.456.789.123:1234");
    options.addArguments("--proxy-auth=username:password");

    WebDriver driver = new ChromeDriver(options);
    driver.manage().window().maximize();

    driver.get("http://2ip.io");`

How can we reproduce the issue?

First code:
`       ChromeOptions options = new ChromeOptions();

        Proxy proxy = new Proxy();
        proxy.setProxyType(Proxy.ProxyType.MANUAL);
        proxy.setAutodetect(false);

        proxy.setSocksProxy("123.456.789.123:1234");
        proxy.setSocksUsername("username");
        proxy.setSocksPassword("password");
        proxy.setSocksVersion(5);

        options.setCapability("proxy", proxy);

        WebDriver driver = new ChromeDriver(options);
        driver.manage().window().maximize();

        driver.get("http://2ip.io");`
Second code:
`        ChromeOptions options = new ChromeOptions();

        options.addArguments("--proxy-server=socks5://123.456.789.123:1234");
        options.addArguments("--proxy-auth=username:password");

        WebDriver driver = new ChromeDriver(options);
        driver.manage().window().maximize();

        driver.get("http://2ip.io");`

Relevant log output

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
. 13, 2024 10:30:16 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
Exception in thread "Thread-2" org.openqa.selenium.WebDriverException: unknown error: net::ERR_SOCKS_CONNECTION_FAILED
  (Session info: chrome=123.0.6312.122)
Build info: version: '4.19.1', revision: 'abe0ee07dc'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.10'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [45090e2209b99e5d9cfa1fea12a69c0f, get {url=р==%7D]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 123.0.6312.122, chrome: {chromedriverVersion: 123.0.6312.122 (31f8248cdd9..., userDataDir: C:\Users\SILENC~1\AppData\L...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:52306}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: windows, proxy: Proxy(manual, socks=95.182...., se:cdp: ws://localhost:52306/devtoo..., se:cdpVersion: 123.0.6312.122, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 45090e2209b99e5d9cfa1fea12a69c0f
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
        at org.openqa.selenium.remote.ErrorCodec.decode(ErrorCodec.java:167)
        at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:138)
        at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:50)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:190)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
        at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:300)
        at com.turbokot.testselenium.CaptchaProcess.run(CaptchaProcess.java:56)
        at java.base/java.lang.Thread.run(Thread.java:842)

Operating System

Windows 10/11

Selenium version

Java 17, org.seleniumhq.selenium:selenium-java:4.19.1

What are the browser(s) and version(s) where you see this issue?

Chrome 123.0.6312.122 (64 bit) (cohort: M123 Rollout)

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 123.0.6312.105

Are you using Selenium Grid?

No response

github-actions[bot] commented 2 months ago

@TurboKoT1, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

HakanBi commented 2 months ago

I encountered the same problem

kaliiiiiiiiii commented 1 month ago

Due to crbug#40829748, Chromium (and therefore Google-Chrome as well) doesn't support socks5 proxies with authentification. This probably affects all languages, not just C-Java.

Possible solution would be to use some middleware proxy server (socks5->middleware->Chrome), such as seleniumwire (Python)