SeleniumHQ / selenium

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

[🐛 Bug]: Cannot open Chrome session with incognito mode along with Bidi CDP #14518

Open datxhoang opened 10 hours ago

datxhoang commented 10 hours ago

What happened?

I would like to open Google Chrome session as incognito mode with Bidi CDP but the Chrome window created then disappear right after then throw the error. I am using:

Just write the simple unit test then you can see the issue.

How can we reproduce the issue?

@Test
    public void test() throws Exception {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("incognito");
        chromeOptions.setCapability("webSocketUrl", true);

        WebDriver webDriver = new CChromeDriver(chromeOptions, 0);
        webDriver.get("https://google.com");
    }

Relevant log output

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Failed to open new tab - no browser is open"}
  (Session info: chrome=128.0.6613.138) 
Host info: host: 'Dats-MacBook-Pro.local', ip: 'fe80:0:0:0:4c2:77b4:a52b:f70c%en0'
Build info: version: '4.22.0', revision: 'c5f3146703'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '14.5', java.version: '17.0.10'
Driver info: com.demo.selenium.driver.CChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [incognito], binary: /Applications/Google Chrome..., extensions: []}, webSocketUrl: true}]}]
  at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:114)
  at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)
  at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:61)
  at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:162)
  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.startSession(RemoteWebDriver.java:232)
  at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161)
  at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:114)
  at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
  at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
  at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:72)

Operating System

MacOS

Selenium version

4.22.0

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

Chrome 128

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

ChromeDriver 128

Are you using Selenium Grid?

No

github-actions[bot] commented 10 hours ago

@datxhoang, 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!

dogukankoylu commented 8 hours ago

Hello,

update it as follows and the problem will be solved.

@Test public void test(){ ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("incognito"); WebDriver driver = new ChromeDriver(chromeOptions); DevTools devTools = ((HasDevTools) driver).getDevTools(); devTools.createSession(); devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty())); driver.get("https://google.com"); }

datxhoang commented 2 hours ago

Hello @dogukankoylu do

My run was says that org.openqa.selenium.devtools.DevToolsException: You are using a no-op implementation of the CDP. The most likely reason for this is that Selenium was unable to find an implementation of the CDP protocol that matches your browser. Please be sure to include an implementation on the classpath, possibly by adding a new (maven) dependency oforg.seleniumhq.selenium:selenium-devtools-vNN:4.22.0whereNNmatches the major version of the browser you're using. Build info: version: '4.22.0', revision: 'c5f3146703' System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '14.5', java.version: '17.0.10' Driver info: DevTools Connection

So it means I have to add the devtool lib into the classpath with the corresponding version. And if yes so let us say, I have a lot of laptops so I have to do it manually for all of them?

datxhoang commented 2 hours ago

More over, I cannot use the Bidi follow your solution above @dogukankoylu

org.openqa.selenium.bidi.BiDiException: Unable to create a BiDi connection Build info: version: '4.22.0', revision: 'c5f3146703' System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '14.5', java.version: '17.0.10' Driver info: BiDi Connection