1

I am trying to get the performance logs of Chromedriver to get access to all network data. The chromedriver is connecting to an Electron app. I tried all the solutions previously discussed here but none seem to work.

caps = DesiredCapabilities.CHROME
caps["goog:loggingPrefs"] = {'performance': 'ALL'}

service = Service(executable_path="./chromedriver.exe")
        
option=Options()
option.binary_location=path.abspath("./tsm-console-desktop.exe")
option.add_argument("remote-debugging-port=9515")


cdriver=webdriver.Chrome(service=service,options=option,desired_capabilities=caps)

I then run

# Electron app loads the set url automatically
cdriver.get_log('browser')

All the answers say to run cdriver.get_log('performance') but Python complains it as invalid argument.

The output log does not have any method information , only console information

{'level': 'SEVERE', 'message': 'https://dev.local.elektaplatform.com/otel-agent/v1/traces - Failed to load resource: the server responded with a status of 404 ()', 'source': 'network', 'timestamp': 1659614239337}

Any ideas?

UPDATE:

Using the executable argument in the WebDriver constructor worked for me, instead of using Service

webdriver.Chrome(executable_path='./chromedriver.exe',options=option,desired_capabilities=caps)

1 Answers1

0

To view the logs, make sure to have the following settings:

  1. Turn on logs by adding the following line to chromedriver.json:

"Logs" : ["stdout"], 2) To get network data, add the following line to chromedriver.json:

"NetworkLogs" : ["stdout"], 3) Add the following line to your command script:

driver.get_log('stdout')

  1. Make sure that the logs are being sent to the console and to the file chromedriver.log

You might be able to get the performance logs by running the following command: chromedriver.get_log('performance'). Also, you may need to install the Python Imaging Library (PIL) in order to get the performance logs.

edit:

It appears that the version of Chromedriver that is bundled with Selenium has problems. I'm not sure if this is a bug in ChromeDriver or a bug in Selenium but it would be nice if they both worked with the bundled version of Chromedriver. I'm guessing it's a bug in ChromeDriver but I've never used it so can't be sure. The solution is to use the headless version of Chromedriver bundled with ChromeDriver and configure Selenium to use that rather than the bundled version. That can be done by passing the following options to the WebDriver driver in the selenium server startup script:

webdriver.chrome.driver=path_to_chromedriver webdriver.chrome.binary=path_to_chrome

You can then use the ChromeOptions() method to select the chrome version. on some systems, the binary was called chrome while the driver was called chromedriver.

To select the headless version of Chromedriver you can use this code:

chromeOptions = (webdriver.ChromeOptions()
.add_argument('--headless')
.set_value('1'))

This will add the headless option to the options for Chrome. You can then set the binary path using the binary option:

chromeOptions.binary = '/path/to/chromedriver'

You can then use the ChromeOptions() method to pass the options to the driver: chromeOptions.add_argument('--user-data-dir=path_to_cache') driver = webdriver.Chrome(chrome_options=chromeOptions)

You will also need to configure the selenium server to use the path to the chromedriver binary in the selenium-server.properties file. You'll need to restart the server after making this change. this can be a good config set up:

selenium.startup.chrome.driver=chromedriver.exe
selenium.startup.chrome.binary=/path/to/chromedriver
selenium.startup.chrome.options=-webdriver.chrome.driver=chromedriver.exe
webdriver.chrome.binary=/path/to/chromedriver

c0d3x27
  • 193
  • 2
  • 15