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

Performance: getEntriesByType() method

· 52CE 我爱测

The **`getEntriesByType()`** method returns an array of PerformanceEntry objects currently present in the performance timeline for a given _type_.

Performance API

The getEntriesByType() method returns an array of PerformanceEntry objects currently present in the performance timeline for a given type.

If you are interested in performance entries of certain name, see Performance.getEntriesByName. For all performance entries, see Performance.getEntries.

[!NOTE] This method does not notify you about new performance entries; you will only get entries that are present in the performance timeline at the time you call this method. To receive notifications about entries as they become available, use a PerformanceObserver.

The following entry types are not supported by this method at all and won't be returned even if entries for these types might exist:

  • "container" (PerformanceContainerTiming)
  • "element" (PerformanceElementTiming)
  • "event" (PerformanceEventTiming)
  • "largest-contentful-paint" (LargestContentfulPaint)
  • "layout-shift" (LayoutShift)
  • "longtask" (PerformanceLongTaskTiming)

To access entries of these types, you must use a PerformanceObserver instead.

Syntax

getEntriesByType(type)

Parameters

  • type
    • : The type of entry to retrieve such as "mark". The valid entry types are listed in PerformanceEntry.entryType. The supported entryTypes can be retrieved using the static property PerformanceObserver.supportedEntryTypes_static.

Return value

An Array of PerformanceEntry objects that have the specified type. The items will be in chronological order based on the entries' PerformanceEntry.startTime. If no objects have the specified type, or no argument is provided, an empty array is returned.

Examples

Logging resource entries

The following example logs all entries with the type "resource".

const resources = performance.getEntriesByType("resource");
resources.forEach((entry) => {
  console.log(`${entry.name}'s startTime: ${entry.startTime}`);
});

Specifications

Browser compatibility

See also

  • Performance.getEntries()
  • Performance.getEntriesByName()
  • PerformanceObserver.supportedEntryTypes_static

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

资料来源与适用范围

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

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

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