getEntriesByName() 方法在 PerformanceObserverEntryList interface returns a list of explicitly observed performance entry objects for a given 名称 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 接口。

句法

entries = list.getEntriesByName(name, type);
					

参数

名称
DOMString representing the name of the entry to retrieve.
type 可选
DOMString representing the type of entry to retrieve such as " mark ". The valid entry types are listed in PerformanceEntry.entryType .

返回值

A list of explicitly observed performance entry objects that have the specified 名称 and type 。若 type argument is not specified, only the 名称 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.

范例

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']});
					

规范

规范 状态 注释
Performance Timeline Level 2
The definition of 'getEntriesByName()' in that specification.
候选推荐 Initial definition of getEntriesByName() 方法。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getEntriesByName Chrome 52 Edge ≤79 Firefox 57 IE No Opera 39 Safari No WebView Android No Chrome Android 52 Firefox Android 57 Opera Android 41 Safari iOS No Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: