Performance: toJSON() メソッド

Baseline Widely available

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

toJSON()Performance インターフェイスのメソッドで、シリアライザーです。パフォーマンスオブジェクトのプロパティの JSON 表現を返します。

構文

js
toJSON()

引数

なし。

返値

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

返された JSON には eventCounts プロパティが格納されていません。これは、EventCounts 型であり、toJSON() 操作を提供していないからです。

メモ: JSON オブジェクトには、非推奨の performance.timing および performance.navigation プロパティのシリアライズが格納されています。新しい PerformanceNavigationTiming インターフェイスの JSON 表現を取得するには、代わりに PerformanceNavigationTiming.toJSON() を呼び出してください。

toJSON メソッドの使用

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

js
performance.toJSON();

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

json
{
  "timeOrigin": 1668077531367.4,
  "timing": {
    "connectStart": 1668077531372,
    "navigationStart": 1668077531367,
    "secureConnectionStart": 0,
    "fetchStart": 1668077531372,
    "domContentLoadedEventStart": 1668077531580,
    "responseStart": 1668077531372,
    "domInteractive": 1668077531524,
    "domainLookupEnd": 1668077531372,
    "responseEnd": 1668077531500,
    "redirectStart": 0,
    "requestStart": 1668077531372,
    "unloadEventEnd": 0,
    "unloadEventStart": 0,
    "domLoading": 1668077531512,
    "domComplete": 1668077531585,
    "domainLookupStart": 1668077531372,
    "loadEventStart": 1668077531585,
    "domContentLoadedEventEnd": 1668077531580,
    "loadEventEnd": 1668077531585,
    "redirectEnd": 0,
    "connectEnd": 1668077531372
  },
  "navigation": {
    "type": 0,
    "redirectCount": 0
  }
}

JSON 文字列を取得するには、 JSON.stringify(performance) を直接使用することができます。

仕様書

Specification
High Resolution Time
# dom-performance-tojson

ブラウザーの互換性

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
toJSON

Legend

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

Full support
Full support

関連情報