I am creating a Chrome Extension. I retrieved the HAR object from the DevTools panel. I am able to get the 'Load' and 'DOMContentLoaded' time from the HAR object,
pages: [
{
"startedDateTime": "2019-03-07T22:16:02.333Z",
"id": "page_2",
"title": "https://xxxx",
"pageTimings": {
"onContentLoad": 1635.4740000006132,
"onLoad": 2318.5020000000804
}
}
]
Now, how do I calculate the 'Finish' time from the HAR object which is 7.75 s as shown below?
So, I have figured it out,
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)