Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long ago did I load a page?

Is there a way to get how long ago a page was loaded using javascript, without having first recorded the time to a javascript variable on page load? I'm hoping to create a scriptlet (javascript bookmark) that I can run on any web page and have it output how much time has passed since the browser loaded the page.

All of the "time spent on a page" solutions I've found so far rely on recording the time when the page first loads, which requires either access to modify a site, or a browser plugin. Is there no document property that stores when the page was loaded (started, finished, etc.) which can be accessed in javascript?

like image 306
Martin Avatar asked Feb 18 '15 17:02

Martin


1 Answers

You could use window.performance.timing.loadEventEnd:

> performance.timing.loadEventEnd
1424280020354

window.performance.timing provides timestamps for the following page load lifecycle events, in order:

  • navigationStart
  • unloadEventStart
  • unloadEventEnd
  • redirectStart
  • redirectEnd
  • fetchStart
  • domainLookupStart
  • domainLookupEnd
  • connectStart
  • connectEnd
  • secureConnectionStart
  • requestStart
  • responseStart
  • responseEnd
  • domLoading
  • domInteractive
  • domContentLoadedEventStart
  • domContentLoadedEventEnd
  • domComplete
  • loadEventStart
  • loadEventEnd

Source: Navigation Timing API on MDN

The Navigation Timing API is currently supported by most modern browsers. Exceptions: Safari < 8 on OSX, Safari on iOS and Opera Mini. - caniuse.com.

like image 87
joews Avatar answered Oct 01 '22 20:10

joews