Performance API
The getEntriesByType() method of the PerformanceObserverEntryList returns a list of explicitly observed PerformanceEntry objects for a given PerformanceEntry.entryType. The list's members are determined by the set of PerformanceEntry.entryType specified in the call to the PerformanceObserver.observe method. The list is available in the observer's callback function (as the first parameter in the callback).
Syntax
getEntriesByType(type)
Parameters
type- : The type of entry to retrieve such as
"mark". The valid entry types are listed in PerformanceEntry.entryType.
- : The type of entry to retrieve such as
Return value
A list of explicitly observed PerformanceEntry objects that have the specified type. The items will be in chronological order based on the entries' PerformanceEntry.startTime. If no objects have the specified type, or no argument is provided, an empty list is returned.
Examples
Working with getEntries, getEntriesByName and getEntriesByType
The following example shows the difference between the PerformanceObserverEntryList.getEntries, PerformanceObserverEntryList.getEntriesByName, and getEntriesByType() methods.
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"],
});
Specifications
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
