PerformanceObserver: phương thức takeRecords()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.

Note: This feature is available in Web Workers.

Phương thức takeRecords() của giao diện PerformanceObserver trả về danh sách hiện tại các đối tượng PerformanceEntry được lưu trong performance observer, đồng thời làm trống nó.

Cú pháp

js
takeRecords()

Tham số

Không có.

Giá trị trả về

Một danh sách các đối tượng PerformanceEntry.

Ví dụ

Lấy các bản ghi

Ví dụ sau lưu danh sách hiện tại các performance entry vào records và làm trống performance observer.

js
const observer = new PerformanceObserver((list, obj) => {
  list.getEntries().forEach((entry) => {
    // Xử lý các sự kiện "mark" và "measure"
  });
});
observer.observe({ entryTypes: ["mark", "measure"] });
const records = observer.takeRecords();
console.log(records[0].name);
console.log(records[0].startTime);
console.log(records[0].duration);

Thông số kỹ thuật

Thông số kỹ thuật
Performance Timeline
# dom-performanceobserver-takerecords

Tương thích trình duyệt