I am trying to retrieve some information like page load time, first paint but also the images and scripts that are being loaded and their sizes.
I am able to detect everything that is being loaded in terms of images and scripts but when I look at the sizes, they do not match the size which I see in my (Firefox) inspector.
Can anyone please explain to me what I am doing wrong?
I would also like to get to know how long it took to load the specific file.
I came up with this code. This shows me the correct name and mimetype, but as said, the file size is not correct.
chromedp.ListenTarget(ctx, func(ev interface{}) {
switch ev := ev.(type) {
case *network.EventResponseReceived:
eventResponseReceived = append(eventResponseReceived, network.EventResponseReceived{
RequestID: ev.RequestID,
LoaderID: ev.LoaderID,
Timestamp: ev.Timestamp,
Type: ev.Type,
Response: ev.Response,
HasExtraInfo: ev.HasExtraInfo,
FrameID: ev.FrameID,
})
case *network.EventLoadingFinished:
eventLoadingFinished = append(eventLoadingFinished, network.EventLoadingFinished{
RequestID: ev.RequestID,
Timestamp: ev.Timestamp,
EncodedDataLength: ev.EncodedDataLength,
ShouldReportCorbBlocking: ev.ShouldReportCorbBlocking,
})
}
})
for i := range eventResponseReceived {
for i2 := range eventLoadingFinished {
if eventResponseReceived[i].RequestID == eventLoadingFinished[i2].RequestID {
fmt.Println(eventResponseReceived[i].Response.URL)
fmt.Println(eventResponseReceived[i].Response.ResponseTime.Time())
fmt.Println(eventResponseReceived[i2].Response.EncodedDataLength)
fmt.Println(eventResponseReceived[i].Response.MimeType)
}
}
}
I found out that I, in some cases, can get the content-length. But for a lot of files the content-length unfortunately is nil.
eventResponseReceived[i2].Response.Headers["content-length"]
So for the files where no content-length was given, I need a solution.