Event: timeStamp プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

timeStampEvent インターフェイスの読み取り専用プロパティで、イベントが作成された時刻(ミリ秒単位)を返します。

この値は、時間の起点からイベントが作成されるまでの経過ミリ秒数です。 グローバルオブジェクトが Window である場合、ユーザーがリンクをクリックした瞬間、または文書の読み込みを開始したスクリプトが時間の起点となります。 ワーカーでは、時間の起点はワーカーが作成された瞬間となります。

値は、5 マイクロ秒(0.005 ミリ秒)精度の DOMHighResTimeStamp ですが、フィンガープリンティングを防ぐために精度が落とされています

HTML

html
<p>
  この iframe にフォーカスを設定していずれかのキーを押下すると、 keypress
  イベントの現在のタイムスタンプを取得します。
</p>
<p>timeStamp: <span id="time">-</span></p>

JavaScript

js
function getTime(event) {
  const time = document.getElementById("time");
  time.firstChild.nodeValue = event.timeStamp;
}
document.body.addEventListener("keypress", getTime);

結果

時間精度の低下

タイミング攻撃やフィンガープリントに対する保護を提供するために、Event.timeStamp の精度はブラウザーの設定によって丸められていることがあります。

Firefox では、privacy.reduceTimerPrecision 環境設定が既定で有効になっており、既定値は 2 ミリ秒になっています。

js
// Firefox での時間精度の低下(既定: 2 ミリ秒)
event.timeStamp;
// 9934
// 10362
// 11670
// …

Firefox では、 privacy.resistFingerprinting も有効にすると、精度は 100 ミリ秒または privacy.resistFingerprinting.reduceTimerPrecision.microseconds の値のうち大きい方になります。

仕様書

Specification
DOM
# ref-for-dom-event-timestamp①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
timeStamp

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.