Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect javascript console output with python

When I'm working in a javascript-heavy application I like to use Console.log() a lot for debugging. However, I want to ensure I've properly suppressed all console logging in production.

I'd like to create a python script to walk through a site and generate a list of pages that write something to the console. I know I could just have it rip through the javascript files before minimization and search for "Console.Log" but I'm often the analyst on a project and consequently don't have access to the codebase. We also have a ton of sites that haven't been touched in a while but could use a scan (great intern project :-) ).

Is this doable with python?

like image 268
Elliott Avatar asked Mar 17 '23 22:03

Elliott


1 Answers

What you can do is to use selenium browser automation tool and check the console logs:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities    

capabilities = DesiredCapabilities.CHROME
capabilities['loggingPrefs'] = { 'browser':'ALL' }

driver = webdriver.Chrome(desired_capabilities=capabilities)

driver.get('http://foo.com')

# print console log messages
for entry in driver.get_log('browser'):
    print entry

Taken from Getting console.log output from Chrome with Selenium Python API bindings.

like image 172
alecxe Avatar answered Mar 27 '23 15:03

alecxe