sitespeedio / chrome-har

Create HAR files from Chrome Debugging Protocol data
MIT License
149 stars 50 forks source link

timings.receive invalid for cached items #62

Open sb8244 opened 4 years ago

sb8244 commented 4 years ago

When I include cached items in my HAR, I get very high receive times for anything cached. I think it's somehow relating when the request was first cached to now, because it increases every time I do a capture.

I fixed it in my project like so:

            const timings = entry.timings || {};
            if (entry.cache.beforeRequest) {
              timings.receive = 0;
            } else {
              timings.receive = formatMillis(
                (params.timestamp - entry._requestTime) * 1000 -
                  entry.__receiveHeadersEnd
              );
            }

I am happy to PR this, although I am not familiar enough with this project to know if it's the right thing to do or not.

P.S. This project is amazing. Doing this by hand would have been such a nightmare, after seeing all of the intricacies here!

soulgalore commented 4 years ago

Hi @sb8244 thanks for creating the issue. I think when we first created this our only focus was on cold cache hits so its probably a couple of bugs for cached items. A PR would be great would be great, I'm thinking your time calculation should fit somewhere in https://github.com/sitespeedio/chrome-har/blob/master/index.js#L259-L264 maybe? I have very limited time the coming weeks but I can help out as much as I can.

Thanks for the kind words :)