MDN self-hosted library · e01.org

Event: timeStamp property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<p>
  Focus this iframe and press any key to get the current timestamp for the
  keypress event.
</p>
<p>timeStamp: <span id="time">-</span></p>
js
function getTime(event) {
  const time = document.getElementById("time");
  time.firstChild.nodeValue = event.timeStamp;
}
document.body.addEventListener("keypress", getTime);
js
// Reduced time precision (1 ms) in a non-isolated context
event.timeStamp;
// Might be:
// 9934
// 10363
// 11671
// …

// Reduced time precision with `privacy.resistFingerprinting` enabled
event.timeStamp;
// Might be:
// 10000.2
// 10016.867
// 10033.534
// …