Search code examples
gochromedp

network usage on chromedp


I am trying to find response size for every request from chromedp I tried following code

chromedp.ListenTarget(
    ctx,
    func(ev interface{}){
        if ev, ok := ev.(*network.EventResponseReceived); ok {
            fmt.Println("event received:")
            fmt.Println(ev.Type)
            var len = ev.Response.EncodedDataLength;
            fmt.Println(ev.Response.URL + ":" + fmt.Sprintf("%f", len))
            return

        }
    },
)

But EncodedDataLength is Total number of bytes received for this request so far (As per documentation). Is there any way to get full response size.

Thanks


Solution

  • You can use EventLoadingFinished.

    Network.loadingFinished #.
    Fired when HTTP request has finished loading. as here

    EventLoadingFinished.EncodedDataLength will give you the full size as this event will be triggered only once the entire response is loaded. You can use both the events and use the RequestID field to map them to a particular resource url.