PerformanceEntry.name - Web API 接口参考 编辑

name 是 PerformanceEntry 接口的属性,此属性的返回值是 PerformanceEntry.entryType 的返回值的一个补充,例如entry.entryType="navigation",entry.name="document". 这是一个只读属性.

Syntax

var name = entry.name;

返回值

返回值取决于PerformanceEntry 对象的 subtype和PerformanceEntry.entryType的值, 如下表所示.

ValueSubtypeentryType valuesDescription
URLPerformanceFrameTiming, PerformanceNavigationTimingframe, navigationThe document's address.
URLPerformanceResourceTimingresourceThe resolved URL of the requested resource. This value doesn't change even if the request is redirected.
DOMStringPerformanceMarkmarkThe name used when the mark was created by calling performance.mark().
DOMStringPerformanceMeasuremeasurename used when the measure was created by calling performance.measure().
DOMStringPerformancePaintTimingpaintEither 'first-paint' or 'first-contentful-paint'.

用例

下面的例子是 name 属性的用法.

function run_PerformanceEntry() {
  log("PerformanceEntry support ...");

  if (performance.mark === undefined) {
    log("... performance.mark Not supported");
    return;
  }

  // Create some performance entries via the mark() method
  performance.mark("Begin");
  do_work(50000);
  performance.mark("End");

  // Use getEntries() to iterate through the each entry
  var p = performance.getEntries();
  for (var i=0; i < p.length; i++) {
    log("Entry[" + i + "]");
    check_PerformanceEntry(p[i]);
  }
}
  //
  //例如上面p中一个entry p[0] = {
  //  "name": "document",
  //  "entryType": "navigation",
  //  "startTime": 0,
  //  "duration": 3611.26,
  //  "initiatorType": "navigation",
  //  "nextHopProtocol": "http/1.1",
  //  "workerStart": 0,
  //  "redirectStart": 0,
  //  "redirectEnd": 0,
  //  "fetchStart": 0.32,
  //  "domainLookupStart": 17.64,
  //  "domainLookupEnd": 17.78,
  //  "connectStart": 17.86,
  //  "connectEnd": 18.1,
  //  "secureConnectionStart": 0,
  //  "requestStart": 18.3,
  //  "responseStart": 294.06,
  //  "responseEnd": 1610.3600000000001,
  //  "transferSize": 97683,
  //  "encodedBodySize": 97112,
  //  "decodedBodySize": 97112,
  //  "unloadEventStart": 1614.8372840721554,
  //  "unloadEventEnd": 1619.1600105887128,
  //  "domInteractive": 3110.767514889843,
  //  "domContentLoadedEventStart": 3125.859851800787,
  //  "domContentLoadedEventEnd": 3438.5779820633365,
  //  "domComplete": 3609.999662153349,
  //  "loadEventStart": 3610.017623620869,
  //  "loadEventEnd": 3611.2672285754975,
  //  "type": "reload",
  //  "redirectCount": 0
  //}

  //下面的函数check_PerformanceEntry的参数obj就是上面的p[0]
  //
function check_PerformanceEntry(obj) {
  var properties = ["name", "entryType", "startTime", "duration"];
  var methods = ["toJSON"];

  for (var i=0; i < properties.length; i++) {
    // check each property
    var supported = properties[i] in obj;
    if (supported)
      log("..." + properties[i] + " = " + obj[properties[i]]);
    else
      log("..." + properties[i] + " = Not supported");
  }
  for (var i=0; i < methods.length; i++) {
    // check each method
    var supported = typeof obj[methods[i]] == "function";
    if (supported) {
      var js = obj[methods[i]]();
      log("..." + methods[i] + "() = " + JSON.stringify(js));
    } else {
      log("..." + methods[i] + " = Not supported");
    }
  }
}

Specifications

SpecificationStatusComment
Performance Timeline Level 2
name
Candidate Recommendation 
Performance Timeline
name
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:77 次

字数:7366

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文