PerformanceObserverEntryList.getEntriesByType()

The getEntriesByType() method of the PerformanceObserverEntryList returns a list of explicitly observed performance entry objects for a given performance 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).

This method is exposed to Window and Worker interfaces.

Syntax

getEntriesByType(type)

Parameters

type

The type of entry to retrieve such as "frame". The valid entry types are listed in PerformanceEntry.entryType.

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' startTime. If no objects have the specified type, or no argument is provided, an empty list is returned.

Examples

function print_perf_entry(pe) {
  console.log(`name: ${pe.name}`);
  console.log(`entryType: ${pe.entryType}`);
  console.log(`startTime: ${pe.startTime}`);
  console.log(`duration: ${pe.duration}`);
}

// Create observer for all performance event types
const observe_all = new PerformanceObserver((list, obs) => {
  // Print all entries
  let perfEntries = list.getEntries();
  perfEntries.forEach((entry) => print_perf_entry(entry));

  // Print entries named "Begin" with type "mark"
  perfEntries = list.getEntriesByName("Begin", "mark");
  perfEntries.forEach((entry) => print_perf_entry(entry));

  // Print entries with type "mark"
  perfEntries = list.getEntriesByType("mark");
  perfEntries.forEach((entry) => print_perf_entry(entry));
});

// Subscribe to all performance event types
observe_all.observe({ entryTypes: ['frame', 'mark', 'measure', 'navigation', 'resource', 'server'] });

const observe_frame = new PerformanceObserver((list, obs) => {
  const perfEntries = list.getEntries();
  // Should only have 'frame' entries
  perfEntries.forEach((entry) => print_perf_entry(entry));
});

// Subscribe to only the 'frame' event
observe_frame.observe({entryTypes: ['frame']});

Specifications

Specification
Performance Timeline
# dom-performanceobserverentrylist-getentriesbytype

Browser compatibility

BCD tables only load in the browser