docs.rodeo

MDN Web Docs mirror

PerformanceEntry: entryType property

{{APIRef("Performance API")}} {{AvailableInWorkers}} 

The read-only entryType property returns a string representing the type of performance metric that this entry represents.

All supported entryTypes are available using the static property {{domxref("PerformanceObserver.supportedEntryTypes_static", "PerformanceObserver.supportedEntryTypes")}} .

Value

A string. The return value depends on the subtype of the PerformanceEntry object. Some subtypes have more than one entryType.

Examples

Filtering performance entries by type

The entryType property can be useful when filtering out specific performance entries. For example, you might want to check all script resources, so you would check for an entryType of "resource" and an {{domxref("PerformanceResourceTiming.initiatorType", "initiatorType")}}  of "script".

const scriptResources = performance
  .getEntries()
  .filter(
    (entry) =>
      entry.entryType === "resource" && entry.initiatorType === "script",
  );
console.log(scriptResources);

Getting performance entries by type

Both, {{domxref("Performance")}}  and {{domxref("PerformanceObserver")}} , provide methods that allow you to get performance entries by type directly. You don’t necessarily need the entryType property for that, instead you might use {{domxref("Performance.getEntriesByType()")}}  or {{domxref("PerformanceObserverEntryList.getEntriesByType()")}} .

Also, when observing with a {{domxref("PerformanceObserver")}} , the {{domxref("PerformanceObserver.observe", "observe()")}}  method takes an array of entryTypes in its options object where you can decide which entry types to observe.

// Log all resource entries at this point
const resources = performance.getEntriesByType("resource");
resources.forEach((entry) => {
  console.log(`${entry.name}'s duration: ${entry.duration}`);
});

// PerformanceObserver version
// Log all resource entries when they are available
function perfObserver(list, observer) {
  list.getEntriesByType("resource").forEach((entry) => {
    console.log(`${entry.name}'s duration: ${entry.duration}`);
  });
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ entryTypes: ["resource", "navigation"] });

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN