PerformanceObserverEntryList: getEntries() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Note: This feature is available in Web Workers.
Phương thức getEntries() của giao diện PerformanceObserverEntryList trả về danh sách các đối tượng mục nhập hiệu suất được quan sát rõ ràng. Các thành viên của danh sách được xác định bởi tập hợp loại mục nhập được chỉ định trong lệnh gọi phương thức observe(). Danh sách có sẵn trong hàm callback của observer (là tham số đầu tiên trong callback).
Cú pháp
getEntries()
Tham số
Không có.
Giá trị trả về
Danh sách các đối tượng PerformanceEntry được quan sát rõ ràng. Các mục sẽ theo thứ tự thời gian dựa trên startTime của các mục nhập. Nếu không tìm thấy đối tượng nào, danh sách rỗng được trả về.
Ví dụ
>Làm việc với getEntries, getEntriesByName và getEntriesByType
Ví dụ sau cho thấy sự khác biệt giữa các phương thức getEntries(), getEntriesByName(), và getEntriesByType().
const observer = new PerformanceObserver((list, obs) => {
// Log all entries
let perfEntries = list.getEntries();
perfEntries.forEach((entry) => {
console.log(`${entry.name}'s duration: ${entry.duration}`);
});
// Log entries named "debugging" with type "measure"
perfEntries = list.getEntriesByName("debugging", "measure");
perfEntries.forEach((entry) => {
console.log(`${entry.name}'s duration: ${entry.duration}`);
});
// Log entries with type "mark"
perfEntries = list.getEntriesByType("mark");
perfEntries.forEach((entry) => {
console.log(`${entry.name}'s startTime: ${entry.startTime}`);
});
});
// Subscribe to various performance event types
observer.observe({
entryTypes: ["mark", "measure", "navigation", "resource"],
});
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Performance Timeline> # dom-performanceobserverentrylist-getentries> |