Skip to content

Instantly share code, notes, and snippets.

@favstats
Created September 9, 2022 19:24
Show Gist options
  • Save favstats/2e51bde9b9bedb4c8bd6547cb6b5e4eb to your computer and use it in GitHub Desktop.
Save favstats/2e51bde9b9bedb4c8bd6547cb6b5e4eb to your computer and use it in GitHub Desktop.
# Import the required modules
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
import json
def get_perf_log_on_load(url, headless = True, filter = None):
# Main Function
# Enable Performance Logging of Chrome.
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities["goog:loggingPrefs"] = {"performance": "ALL"}
# Create the webdriver object and pass the arguments
options = webdriver.ChromeOptions()
# Chrome will start in Headless mode
options.add_argument('headless')
# Ignores any certificate errors if there is any
options.add_argument("--ignore-certificate-errors")
# Startup the chrome webdriver with executable path and
# pass the chrome options and desired capabilities as
# parameters.
driver = webdriver.Chrome(options=options,
desired_capabilities=desired_capabilities)
# Send a request to the website and let it load
driver.get(url)
# Sleeps for 10 seconds
time.sleep(2)
# Gets all the logs from performance in Chrome
logs = driver.get_log("performance")
driver.close()
return logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment