The DOMHighResTimeStamp
type is a double
and is used to store a time value. The value could be a discrete point in time or the difference in time between two discrete points in time.
The unit is milliseconds and should be accurate to 5 µs (microseconds). However, if the browser is unable to provide a time value accurate to 5 microseconds (due, for example, to hardware or software constraints), the browser can represent the value as a time in milliseconds accurate to a millisecond. Also note the section below on reduced time precision controlled by browser preferences to avoid timing attacks and fingerprinting.
Further, if the device or operating system the user agent is running on doesn't have a clock accurate to the microsecond level, they may only be accurate to the millisecond.
To offer protection against timing attacks and fingerprinting, the precision of time stamps might get rounded depending on browser settings.
In Firefox, the privacy.reduceTimerPrecision
preference is enabled by default and defaults to 20us in Firefox 59; in 60 it will be 2ms.
// reduced time precision (2ms) in Firefox 60 event.timeStamp // 1519211809934 // 1519211810362 // 1519211811670 // ... // reduced time precision with `privacy.resistFingerprinting` enabled event.timeStamp; // 1519129853500 // 1519129858900 // 1519129864400 // ...
In Firefox, you can also enabled privacy.resistFingerprinting
, the precision will be 100ms or the value of privacy.resistFingerprinting.reduceTimerPrecision.microseconds
, whichever is larger.
This type has no properties. It is a double-precision floating-point value.
The value of a DOMHighResTimeStamp
is a double-precision floating-point number which describes the number of milliseconds (accurate to within 5 microseconds if the device supports it) elapsed between two points in time. The starting time can be either a specific time determined by the script for a site or app, or the time origin.
The time origin is a standard time which is considered to be the beginning of the current document's lifetime. It's calculated like this:
Window
, the time origin is determined as follows: Document
is the first one loaded in the Window
, the time origin is the time at which the browser context was created.Document
took place.WorkerGlobalScope
(that is, the script is running as a web worker), the time origin is the moment at which the worker was created.This type has no methods.
Specification | Status | Comment |
---|---|---|
High Resolution Time Level 2 The definition of 'DOMHighResTimeStamp' in that specification. | Candidate Recommendation | Stricter definitions of interfaces and types. |
High Resolution Time The definition of 'DOMHighResTimeStamp' in that specification. | Recommendation | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 6 | Yes | 7 | 9 | 15 | 8 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | 18 | Yes | 15 | 15 | 9 | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp