如何计算来自HAR对象的Chrome DevTools网络选项卡中显示的“完成”时间?

问题描述 投票:0回答:1

我正在创建Chrome扩展程序。我从DevTools面板中检索了HAR对象。我能够从HAR对象获得'Load'和'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秒,如下所示?

enter image description here

google-chrome browser google-chrome-extension google-chrome-devtools har
1个回答
0
投票

所以,我已经弄明白了,

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)
© www.soinside.com 2019 - 2024. All rights reserved.