Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. Web API
  3. PerformanceEntry

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

PerformanceEntry

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2017年9月⁩.

PerformanceEntry 对象代表了 performance 时间列表中的单个 metric 数据。每一个performance entry 都可以在应用运行过程中通过手动构建mark 或者measure (例如调用mark() 方法) 生成。此外,Performance entries 在资源加载的时候,也会被动生成(例如图片、script、css 等资源加载)

Note: Performance 对象暴露给了WindowWorker. 同时该对象扩展了几个其他对象的属性,包括PerformanceMark,PerformanceMeasure,PerformanceFrameTiming,PerformanceNavigationTiming 以及PerformanceResourceTiming.

Properties

PerformanceEntry.name只读

DOMString 该 performance entry 的名字

PerformanceEntry.entryType只读

DOMString 代表所上报的 performance metric 的 entryType 类型,例如 "mark". 可以通过entryType 查阅完整的 entryType type 类型。

PerformanceEntry.startTime只读

DOMHighResTimeStamp 此为 metric 上报时的时间

PerformanceEntry.duration只读

DOMHighResTimeStamp 该事件的耗时

Methods

PerformanceEntry.toJSON()

返回PerformanceEntry 对象的 JSON 格式数据

Example

以下例子检查了当前浏览器所支持的所有PerformanceEntry 属性,每个属性的检查结果都会通过 console 打印出来

js
function print_PerformanceEntries() {  // Use getEntries() to get a list of all performance entries  var p = performance.getEntries();  for (var i = 0; i < p.length; i++) {    console.log("PerformanceEntry[" + i + "]");    print_PerformanceEntry(p[i]);  }}function print_PerformanceEntry(perfEntry) {  var properties = ["name", "entryType", "startTime", "duration"];  for (var i = 0; i < properties.length; i++) {    // check each property    var supported = properties[i] in perfEntry;    if (supported) {      var value = perfEntry[properties[i]];      console.log("... " + properties[i] + " = " + value);    } else {      console.log("... " + properties[i] + " = NOT supported");    }  }}

Specifications

Specification
Performance Timeline
# dom-performanceentry

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp