PerformanceEventTiming: toJSON() メソッド

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

toJSON()PerformanceEventTiming インターフェイスのメソッドで、シリアライザーです。これは PerformanceEventTiming オブジェクトの JSON 表現を返します。

構文

js
toJSON()

引数

なし。

返値

PerformanceEventTiming オブジェクトをシリアライズした JSON オブジェクトです。

JSON は target プロパティを含みません。これは Node 型であり、 toJSON() 処理を提供していないからです。

toJSON メソッドの使用

この例では、entry.toJSON() を呼び出すと、 PerformanceEventTiming オブジェクトの JSON 表現が返されます。

js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    console.log(entry.toJSON());
  });
});

observer.observe({ type: "event", buffered: true });

このように JSON オブジェクトをログ出力します。

json
{
  "name": "dragover",
  "entryType": "event",
  "startTime": 67090751.599999905,
  "duration": 128,
  "processingStart": 67090751.70000005,
  "processingEnd": 67090751.900000095,
  "cancelable": true
}

JSON 文字列を取得するには、 JSON.stringify(entry) を直接使用することができます。これは toJSON() を自動的に呼び出します。

仕様書

Specification
Event Timing API
# dom-performanceeventtiming-tojson

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
toJSON

Legend

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

Full support
Full support
No support
No support

関連情報