ReportingObserver: takeRecords() method

Baseline 2026
Newly available

Since March 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

Phương thức takeRecords() của giao diện ReportingObserver trả về danh sách báo cáo hiện tại chứa trong hàng đợi báo cáo của observer, và làm rỗng hàng đợi.

Cú pháp

js
takeRecords()

Tham số

Không có.

Giá trị trả về

Một mảng các đối tượng báo cáo, chẳng hạn như COEPViolationReportIntegrityViolationReport.

Các từ điển đối tượng được liệt kê trong Reporting API.

Ví dụ

Sử dụng cơ bản

js
const options = {
  types: ["deprecation"],
  buffered: true,
};

const observer = new ReportingObserver((reports, observer) => {
  reportBtn.onclick = () => displayReports(reports);
}, options);

observer.observe();

// …

const records = observer.takeRecords();
console.log(records);

Thông số kỹ thuật

Specification
Reporting API
# dom-reportingobserver-takerecords

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

Xem thêm