PerformanceObserver: takeRecords() 方法
注意:此功能在 Web Workers 中可用。
takeRecords() 方法是 PerformanceObserver 接口的一部分,它会返回性能观察器中存储的当前 PerformanceEntry 对象列表,并清空该列表。
语法
js
takeRecords()
参数
无。
返回值
一个 PerformanceEntry 对象列表。
示例
获取记录
下面的示例将性能条目(performance entries)的当前列表存储在 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);
规范
| 规范 |
|---|
| 性能时间线 # dom-performanceobserver-takerecords |
浏览器兼容性
加载中…