PerformanceEntry: 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() メソッドはシリアライザーで、この PerformanceEntry オブジェクトの JSON 表現を返します。

構文

js
toJSON()

引数

なし。

返値

JSON お武衛ジェクトで、この PerformanceEntry オブジェクトをシリアライズしたものです。

toJSON メソッドの使用

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

js
performance.mark("debug-marker", {
  detail: "debugging-marker-123",
});

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

observer.observe({ entryTypes: ["mark"] });

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

json
{
  "name": "debug-marker",
  "entryType": "mark",
  "startTime": 158361,
  "duration": 0
}

PerformanceMarkdetail プロパティが格納されていないことに注意してください。

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

仕様書

Specification
Performance Timeline
# dom-performanceentry-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

関連情報