selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: Can't capture full Object structures in console log

Open zerosdev opened this issue 1 year ago • 7 comments

What happened?

I'm trying to get the full log messages in console (Chrome) but the log captured is only "Object" when in real browser we can expand object structures. Is there any possibility to capture the full object values?

How can we reproduce the issue?

  1. Add logger to the webdriver instance to print log message in Terminal
const logs: logging.Entry[] = await driver.manage().logs().get(logging.Type.BROWSER);
console.log(logs);
  1. Create a webpage than print an object in the browser's console
<script>console.warn(JSON.parse(`{"key":"value"}`));</script>
  1. Navigate to that webpage

  2. Check terminal messages

Relevant log output

[WARNING] [2024-05-27T08:20:34.139Z] http://localhost:8000/console.html 6:16 Object

Operating System

MacOS X

Selenium version

Javascript 4.7.1

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

Chrome 125

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

Chromedriver 125

Are you using Selenium Grid?

No

zerosdev avatar May 27 '24 08:05 zerosdev

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

github-actions[bot] avatar May 27 '24 08:05 github-actions[bot]

Those APIs will be using BiDi in the future, you can see an examples here: https://www.selenium.dev/documentation/webdriver/bidirectional/webdriver_bidi/log/

You also need to upgrade to the latest Selenium version to use them.

diemol avatar May 27 '24 09:05 diemol

Those APIs will be using BiDi in the future, you can see an examples here: https://www.selenium.dev/documentation/webdriver/bidirectional/webdriver_bidi/log/

You also need to upgrade to the latest Selenium version to use them.

Thanks, i'm trying to implement BiDi in the latest version of Selenium but i got this error :

TypeError: Cannot read properties of undefined (reading 'replace') at thenableWebDriverProxy.getBidi (node_modules/selenium-webdriver/lib/webdriver.js:1261:34) at LogInspector.init (node_modules/selenium-webdriver/bidi/logInspector.js:41:17) at Object.getLogInspectorInstance [as LogInspector] (node_modules/selenium-webdriver/bidi/logInspector.js:259:3)

Here is the piece of code where the error produced:

async getBidi() {
    const caps = await this.getCapabilities()
    let WebSocketUrl = caps['map_'].get('webSocketUrl')
    return new BIDI(WebSocketUrl.replace('localhost', '127.0.0.1'))
  }

zerosdev avatar May 27 '24 10:05 zerosdev

Can you share your code?

diemol avatar May 27 '24 10:05 diemol

Here are the main functions:

public constructor(browserConfig?: BrowserConfig) {
  // default values
  this.browserConfig = {
    downloadPath: environment.DOWNLOADS_PATH ?? `../builds/qa/automation/downloads`,
    headless: environment.headless ?? false,
    incognito: environment.incognito ?? true,
    ...browserConfig,
  };

  this.driver = Browser.createBrowser(this.browserConfig);
  // add ability to upload from local machine to remote webdriver
  this.driver.setFileDetector(new FileDetector());
}

public async enableBidiLogging(): Promise<void> {
  const inspector = await LogInspector(this.driver);
  await inspector.onConsoleEntry((log: ConsoleLogEntry) => this.consoleLogs.push(log));
  await inspector.onJavascriptLog((log: JavascriptLogEntry) => this.javascriptLogs.push(log));
  await inspector.onJavascriptException((log: JavascriptLogEntry) => this.javascriptLogs.push(log));
}

private static createBrowser(browserConfig: BrowserConfig): ThenableWebDriver {
    const options: Options = new Options();
        options.addArguments(
          '--no-sandbox',
          `--window-size=${environment.screen}`,
          '--disable-dev-shm-usage',
          '--disable-web-security',
          '--allow-running-insecure-content',
          '--disable-cache',
          'disable-popup-blocking',
          // `--proxy-server=${environment.PROXY_SERVER}`,
        );
        if (browserConfig.incognito) {
          options.addArguments('--incognito');
        }
        if (browserConfig.headless) {
          options.addArguments('--headless');
        }
        const prefs: any = {
          'directory_upgrade': true,
          'disable-popup-blocking': true,
          'download.directory_upgrade': true,
          'download.prompt_for_download': false,
          'plugins.always_open_pdf_externally': true, // force download pdf file
          'profile.content_settings.exceptions.automatic_downloads.*.setting': 1,
          'profile.default_content_settings.popups': 0,
          'safebrowsing.enabled': false,
        };
        options.setUserPreferences(prefs);

        return new Builder().forBrowser('chrome').setChromeOptions(options).build();
}

So, i call enableBidiLogging() before opening an url and that error occurs

zerosdev avatar May 27 '24 10:05 zerosdev

Did you check the code examples I linked above?

Check how the browser is started: https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk//examples/javascript/test/bidirectional/logInspector.spec.js#L10-L15

diemol avatar May 27 '24 10:05 diemol

+1 to Diego's comment. You need to enableBiDi() for the code to work.

pujagani avatar May 27 '24 10:05 pujagani

This issue was closed because we did not receive any additional information after 14 days.

github-actions[bot] avatar Jun 12 '24 10:06 github-actions[bot]

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

github-actions[bot] avatar Jul 12 '24 22:07 github-actions[bot]