selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: 4.1 CDP Browser connection is not being set to a browser connection

Open zackasaurus opened this issue 3 years ago • 3 comments

What happened?

It works expected in version 4.0, but when I upgrade to 4.1, I get the error: { id: 2, error: { code: -32601, message: "'SystemInfo.getProcessInfo' wasn't found" }, sessionId: 'B0F2F63E41CD226149487BF5A8D1817A' }

@pujagani

How can we reproduce the issue?

{
  "name": "selenium-4.1-cdp-bug",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@types/selenium-webdriver": "^4.0.16",
    "edgedriver": "^4.17134.1",
    "selenium-webdriver": "^4.1.1"
  }
}


import "edgedriver";
import edge from "selenium-webdriver/edge";

async function example() {
  const edgeService = new edge.ServiceBuilder(
    "C:/Program Files (x86)/Microsoft/Edge/Application/msedgedriver.exe"
  )
    .setPort(55555)
    .build();

  const options = new edge.Options();
  // configure browser options ...

  const driver = edge.Driver.createSession(options, edgeService);
  //To wait for browser to build and launch properly

  await driver.get("about:blank");

  const browserConnection = await driver.createCDPConnection("browser");

  browserConnection._wsConnection.on("message", (data) => {
    /**
     * {
      id: 2,
      error: { code: -32601, message: "'SystemInfo.getProcessInfo' wasn't found" },
      sessionId: 'B0F2F63E41CD226149487BF5A8D1817A'
        }
     */
    console.log(JSON.parse(data));
  });

  await browserConnection.execute("SystemInfo.getProcessInfo", {});

  await driver.sleep(1000);
  //It is always a safe practice to quit the browser after execution
  await driver.quit();
}

example();

Relevant log output

{
  id: 2,
  error: { code: -32601, message: "'SystemInfo.getProcessInfo' wasn't found" },
  sessionId: 'B0F2F63E41CD226149487BF5A8D1817A'
}

Operating System

Windows 11

Selenium version

Javascript Selenium Webdriver

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

Edge 97.0.1072.76

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

Edge Driver ^4.17134.1

Are you using Selenium Grid?

4.1.1

zackasaurus avatar Feb 02 '22 15:02 zackasaurus

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

github-actions[bot] avatar Feb 02 '22 15:02 github-actions[bot]

The short answer is, Selenium doesn't support this.

One of the JS devs will have to give the longer answer, because I don't understand what JS is doing with DevTools. Presumably Selenium is only officially supporting a handful of Chrome DevTools domains directly right now (https://github.com/SeleniumHQ/selenium/tree/trunk/java/src/org/openqa/selenium/devtools/v98), but looking at the JS code I can't figure out what is getting generated where.

There is an endpoint goog/cdp/execute that would allow Selenium to pass along any dev tools command via the driver, but it isn't officially supported by Selenium, and it doesn't look like JS implements it, and I'm not sure if that's on purpose.

titusfortner avatar Feb 07 '22 01:02 titusfortner

Thank you Titus for providing the context. Appreciate it. @zackasaurus Thank you for sharing the details. However, I am unable to reproduce the error. I use the following example:

const webdriver = require('selenium-webdriver');
const BROWSER_NAME = webdriver.Browser.EDGE;

async function getDriver() {
  return new webdriver.Builder()
  .usingServer('http://localhost:4444')
  .forBrowser(BROWSER_NAME)
  .build();
}

async function executeCDPCommands () {

let driver = await getDriver();
 await driver.get("https://www.google.com");
  
 await driver.get("about:blank");

 const browserConnection = await driver.createCDPConnection('browser');

 browserConnection._wsConnection.on("message", (data) => {
   /**
    * {
     id: 2,
     error: { code: -32601, message: "'SystemInfo.getProcessInfo' wasn't found" },
     sessionId: 'B0F2F63E41CD226149487BF5A8D1817A'
       }
    */
   console.log(JSON.parse(data));
 });

 await browserConnection.execute("SystemInfo.getProcessInfo", {});
 
 await driver.quit();
}

executeCDPCommands(); 

With 4.0 and 4.1 I see the error:

{
  error: { code: -32600, message: "Message must have integer 'id' property" }
}

I tried a similar example with Java. However, Java does not allow creating a browser connection. It only supports the page target. With both 4.0 and 4.1 I see the error: Exception in thread "main" org.openqa.selenium.devtools.DevToolsException: {"id":5,"error":{"code":-32601,"message":"'SystemInfo.getProcessInfo' wasn't found"},"sessionId":"66C40F947CEC9DDED6DB188BF066813F"}

MSEdge and MSEdge driver Version: 98.0.1108.43

The error you are getting usually happens when CDP does not support that command. It is very unlikely that the issue is related to Selenium's CDP implementation.

pujagani avatar Feb 11 '22 12:02 pujagani

I am going to close this as we could not verify this is an issue in Selenium itself, also because we did not get more information from the OP.

diemol avatar Aug 10 '22 13:08 diemol

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Sep 10 '22 00:09 github-actions[bot]