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

PerformanceEntry.entryType

· 52CE 我爱测

The **`entryType`** 返回一个代表 performance metric 类型的String , 例如被 performance.mark("begin") 所创建的 entry 的 entryType 就是 "`mark`". 此属性只读。

Performance Timeline API

The entryType 返回一个代表 performance metric 类型的String , 例如被 performance.mark("begin") 所创建的 entry 的 entryType 就是 "mark". 此属性只读。

语法

var type = entry.entryType;

返回值

返回值取决于 PerformanceEntry 对象的 subtype,entryType 的取值会影响PerformanceEntry.name 属性,具体如下表所示。

Value Subtype Type of name property Description of name property
frame, navigation PerformanceFrameTiming, PerformanceNavigationTiming URL The document's address.
resource PerformanceResourceTiming URL The resolved URL of the requested resource. This value doesn't change even if the request is redirected.
mark PerformanceMark String The name used when the mark was created by calling Performance.mark.
measure PerformanceMeasure String name used when the measure was created by calling Performance.measure.
paint PerformancePaintTiming String Either 'first-paint' or 'first-contentful-paint'.

范例

下面的代码说明了 entryType 属性的用法。

function run_PerformanceEntry() {
  // check for feature support before continuing
  if (performance.mark === undefined) {
    console.log("performance.mark not supported");
    return;
  }

  // Create a performance entry named "begin" via the mark() method
  performance.mark("begin");

  // Check the entryType of all the "begin" entries
  var entriesNamedBegin = performance.getEntriesByName("begin");
  //entriesNamedBegin
  //    Array [ PerformanceMark ]
  //entriesNamedBegin[0]
  //    PerformanceMark { name: "begin", entryType: "mark", startTime: 94661370.14, duration: 0 }
  //entriesNamedBegin[0].entryType
  //    "mark"
  //entriesNamedBegin[0].name
  //    "begin"

  for (var i = 0; i < entriesNamedBegin.length; i++) {
    var typeOfEntry = entriesNamedBegin[i].entryType;
    console.log("Entry is type: " + typeOfEntry);
  }
}

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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