【问题标题】:How to calculate the 'Finish' time shown in Chrome DevTools Network tab from the HAR object?如何从 HAR 对象计算 Chrome DevTools Network 选项卡中显示的“完成”时间?
【发布时间】:2019-07-29 22:58:49
【问题描述】:

我正在创建一个 Chrome 扩展程序。我从 DevTools 面板中检索了 HAR 对象。我能够从 HAR 对象中获取“加载”和“DOMContentLoaded”时间,

pages: [
  {
    "startedDateTime": "2019-03-07T22:16:02.333Z",
    "id": "page_2",
    "title": "https://xxxx",
    "pageTimings": {
      "onContentLoad": 1635.4740000006132,
      "onLoad": 2318.5020000000804
    }
  }
]

现在,我如何计算 HAR 对象的“完成”时间,即 7.75 秒,如下所示?

【问题讨论】:

  • “完成”是请求按时间戳排序时,最后一个请求和第一个请求的时间戳之差。
  • @wOxxOm 认为它实际上是 FinishTime=(lastRequestStartedTime + lastRequestDuration) - (firstRequestStartedTime)

标签: google-chrome browser google-chrome-extension google-chrome-devtools har


【解决方案1】:

所以,我想通了,

FinishTime=(lastRequestStartedTime + lastRequestDuration) - (firstRequestStartedTime)

const requests=harObject.entries;

const lastRequest = requests.reduce(
    (a, b) => {
      return a.startedDateTime > b.startedDateTime ? a : b;
    }
  );

const firstRequest = requests.reduce(
    (a, b) => {
      return a.startedDateTime < b.startedDateTime ? a : b;
    }
  );

//Finish Time in Seconds
const finishTime=`((Date.parse(lastRequest.startedDateTime) + lastRequest.time
                  - Date.parse(firstRequest.startedDateTime))
                  / 1000).toFixed(2)

【讨论】:

  • (lastRequestStartedTime + lastRequestTime) - (lastRequestStartedTime) ...这不就是标准数学中的lastRequestTime吗?
  • @JaromandaX 哎呀!我犯了一个错误。这是(lastRequestStartedTime + lastRequestDuration) - (firstRequestStartedTime) 我编辑了答案。如果你读过代码,你就会明白我想说什么。感谢您指出。
猜你喜欢
  • 2020-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-19
  • 2013-12-04
  • 2014-02-22
相关资源
最近更新 更多