dpwr
dpwr

Reputation: 2812

Get all Chrome browser (including service worker and extension) logs with Selenium

I know how to get logs from the browser in Selenium as shown below, but the problem with this is that some of the logs I can see in the browser's console, are never captured by Selenium. These missing logs are from extensions and service workers.

Is there any way to capture the logs from extensions and service workers? I am not able to modify the extensions or service workers to use an alternate logging mechanism, but any other workarounds would be most welcome!

# Initialise the driver, enabling browser logging
options = webdriver.ChromeOptions()
...
capabilities = options.to_capabilities()
capabilities['goog:loggingPrefs'] = { 'browser': 'ALL' }
driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get('http://127.0.0.1')
# Continually log everything
while True:
    for entry in driver.get_log('browser'):
        print(entry)

Upvotes: 5

Views: 657

Answers (1)

SofianD
SofianD

Reputation: 47

This library allows you to get logs of the browser: https://github.com/MarketSquare/robotframework-seleniumtestability I have used it in the past to retrieve browser logs but I'm not sure about extenstions, you could give it a try. enter image description here

Upvotes: 1

Related Questions