我正在创建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秒,如下所示?
所以,我已经弄明白了,
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)