PerformanceObserverEntryList.getEntriesByName()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

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).

This method is exposed to Window and Worker interfaces.

Syntax

JavaScript
entries = list.getEntriesByName(name, type);

Parameters

name
A DOMString representing the name of the entry to retrieve.
type Optional
A DOMString representing the type of entry to retrieve such as "mark". The valid entry types are listed in PerformanceEntry.entryType.

Return value

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.

Example

JavaScript
function print_perf_entry(pe) {
  console.log("name: "        + pe.name      +
              "; entryType: " + pe.entryType +
              "; startTime: " + pe.startTime +
              "; duration: "  + pe.duration);
}

// Create observer for all performance event types
var observe_all = new PerformanceObserver(function(list, obs) {
  var perfEntries;

  // Print all entries
  perfEntries = list.getEntries();
  for (var i=0; i < perfEntries.length; i++) {
    print_perf_entry(perfEntries[i]);
  }

  // Print entries named "Begin" with type "mark"
  perfEntries = list.getEntriesByName("Begin", "mark");
  for (var i=0; i < perfEntries.length; i++) {
    print_perf_entry(perfEntries[i]);
  }

  // Print entries with type "mark"
  perfEntries = list.getEntriesByType("mark");
  for (var i=0; i < perfEntries.length; i++) {
    print_perf_entry(perfEntries[i]);
  }
});
// subscribe to all performance event types
observe_all.observe({entryTypes: ['frame', 'mark', 'measure', 'navigation', 'resource', 'server']});

var observe_frame = new PerformanceObserver(function(list, obs) {
  var perfEntries = list.getEntries();
  // Should only have 'frame' entries
  for (var i=0; i < perfEntries.length; i++) {
    print_perf_entry(perfEntries[i]);
  }
});
// subscribe to only the 'frame' event
observe_frame.observe({entryTypes: ['frame']});

Specifications

Specification Status Comment
Performance Timeline Time Level 2
The definition of 'getEntriesByName()' in that specification.
Editor's Draft Initial definition of getEntriesByName() method.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
getEntriesByName() 52.0 49 (49)[1] No support 39 No support
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
getEntriesByName() No support No support 49.0 (49)[1] No support No support 39 No support 52.0

[1] Only activated in Nightly builds. Controlled by the dom.enable_performance_observer preference.  

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/performanceobserverentrylist/getentriesbyname

API Method PerformanceObserverEntryList Reference Web Performance