PerformanceObserver: takeRecords() メソッド
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2021年9月以降、すべてのブラウザーで利用可能です。
takeRecords() は PerformanceObserver インターフェイスのメソッドで、パフォーマンスオブザーバーに格納されているパフォーマンス項目の現在のリストを空にして返します。
構文
js
takeRecords()
引数
なし。
返値
PerformanceEntry オブジェクトのリストです。
例
>記録を取る
次の例は、現在のパフォーマンス項目のリストを records に格納し、パフォーマンスオブザーバーを空にします。
js
const observer = new PerformanceObserver((list, obj) => {
list.getEntries().forEach((entry) => {
// Process "mark" and "measure" events
});
});
observer.observe({ entryTypes: ["mark", "measure"] });
const records = observer.takeRecords();
console.log(records[0].name);
console.log(records[0].startTime);
console.log(records[0].duration);
仕様書
| 仕様書 |
|---|
| Performance Timeline> # dom-performanceobserver-takerecords> |