The getEntriesByName()
method of the PerformanceObserverEntryList
interface returns a list of explicitly observed performance entry objects for a given name
and entry type
. The list's members are determined by the set of entry types specified in the call to the observe()
method. The list is available in the observer's callback function (as the first parameter in the callback).
getEntriesByName(name)
getEntriesByName(name, type)
A list of explicitly observed performance entry objects that have the specified name
and type
. If the type
argument is not specified, only the name
will be used to determine the entries to return. The items will be in chronological order based on the entries' startTime
. If no objects meet the specified criteria, an empty list is returned.
The following example shows the difference between the getEntries()
, getEntriesByName()
, and getEntriesByType()
methods.
const observer = new PerformanceObserver((list, obs) => {
let perfEntries = list.getEntries();
perfEntries.forEach((entry) => {
console.log(`${entry.name}'s duration: ${entry.duration}`);
});
perfEntries = list.getEntriesByName("debugging", "measure");
perfEntries.forEach((entry) => {
console.log(`${entry.name}'s duration: ${entry.duration}`);
});
perfEntries = list.getEntriesByType("mark");
perfEntries.forEach((entry) => {
console.log(`${entry.name}'s startTime: ${entry.startTime}`);
});
});
observer.observe({
entryTypes: ["mark", "measure", "navigation", "resource"],
});