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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With