PerformanceObserver: takeRecords() メソッド

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);

仕様書

Specification
Performance Timeline
# dom-performanceobserver-takerecords

ブラウザーの互換性

BCD tables only load in the browser