Search code examples
google-chromepageload

Script Page Load / Chrome's finish


I'm looking for a way to get the page load of a website.

Namely the "finish" value from chrome network tab:

enter image description here

I want to compare websites, so the value must not be exactly like in chrome, just comparable between websites.

I basically want to answer the question "How does my Page Load time compare to other websites".

I tried things like yslow.js (buggy) and tried with selenium and other headless browser but was not able to figure that out.


Solution

  • You can get these metrics from window.performance.timing.

    Here is an example with Python :

    from selenium import webdriver
    
    driver = webdriver.Chrome()
    
    driver.get(r"http://stackoverflow.com/")
    
    times = driver.execute_script("""
      var t = window.performance.timing; return [
        t.domContentLoadedEventEnd - t.navigationStart,
        t.loadEventEnd - t.navigationStart
      ]; """)
    
    print "DOMContentLoaded: %s  Load: %s" % tuple(times)