大网数据广告活动
Web 标准与前端开发

PerformanceObserverEntryList: getEntries() method

· 52CE 我爱测

The **`getEntries()`** method of the PerformanceObserverEntryList interface returns a list of explicitly observed PerformanceEntry objects. The list's members are determined by the set of PerformanceEntry.entryType specified in the call to the PerformanceObserver.observe method.

Performance API

The getEntries() method of the PerformanceObserverEntryList interface returns a list of explicitly observed PerformanceEntry objects. The list's members are determined by the set of PerformanceEntry.entryType specified in the call to the PerformanceObserver.observe method. The list is available in the observer's callback function (as the first parameter in the callback).

Syntax

getEntries()

Parameters

None.

Return value

A list of explicitly observed PerformanceEntry objects. The items will be in chronological order based on the entries' PerformanceEntry.startTime. If no objects are found, an empty list is returned.

Examples

Working with getEntries, getEntriesByName and getEntriesByType

The following example shows the difference between the getEntries(), PerformanceObserverEntryList.getEntriesByName, and PerformanceObserverEntryList.getEntriesByType methods.

const observer = new PerformanceObserver((list, obs) => {
  // Log all entries
  let perfEntries = list.getEntries();
  perfEntries.forEach((entry) => {
    console.log(`${entry.name}'s duration: ${entry.duration}`);
  });

  // Log entries named "debugging" with type "measure"
  perfEntries = list.getEntriesByName("debugging", "measure");
  perfEntries.forEach((entry) => {
    console.log(`${entry.name}'s duration: ${entry.duration}`);
  });

  // Log entries with type "mark"
  perfEntries = list.getEntriesByType("mark");
  perfEntries.forEach((entry) => {
    console.log(`${entry.name}'s startTime: ${entry.startTime}`);
  });
});

// Subscribe to various performance event types
observer.observe({
  entryTypes: ["mark", "measure", "navigation", "resource"],
});

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。