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 2017年10月.
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
}
PerformanceMark の detail プロパティが格納されていないことに注意してください。
JSON 文字列を取得するには、 JSON.stringify(entry) を直接使用することができます。これは toJSON() を自動的に呼び出します。
仕様書
| Specification |
|---|
| Performance Timeline> # dom-performanceentry-tojson> |
ブラウザーの互換性
Loading…