sitespeedio / chrome-har

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

Why are responseFailed requests excluded from the HAR entries #60

Closed taylorfinnell closed 4 years ago

taylorfinnell commented 4 years ago

It looks like when a har is created from the messages any entry that is a responseFailed is filtered out of the entry list. For my usecase I would like to know when a fired requests returns say a 403. Is this possible in some way?

soulgalore commented 4 years ago

Can you show me where? It shouldn't be, as long as we get a response it should be included.

taylorfinnell commented 4 years ago

Sorry, looks like I meant loadingFailed. But it happens here

https://github.com/sitespeedio/chrome-har/blob/master/index.js#L494

soulgalore commented 4 years ago

If I remember it was as of the comment above see https://github.com/sitespeedio/chrome-har/blob/master/index.js#L487 the HAR spec don't support it but it would be cool to support requests that never get a response in one way or another.

taylorfinnell commented 4 years ago

Agreed. It shows up in the Chrome network tools, so I think I would expect it in the HAR. It seems to me the entry would still have a response object on it? The response object would just have a status of 403 and whatever else. If that's the case would it be enough to just remove the filter inside the loadedFailed block? Or does it not have a response object and get filtered out https://github.com/sitespeedio/chrome-har/blob/master/index.js#L543 anyway? If it does not actually get a response object on the entry would an option that allows inclusion of entries with no response make sense to add?

soulgalore commented 4 years ago

I think loadingFailed in this context means the server doesn't respond until the browser timeout.

taylorfinnell commented 4 years ago

I logged the blockedReason on the event using this code. The reason is net::ERR_ABORTED, so it doesn't seem to be a browser timeout. Also, the request completes in a few hundred milliseconds in the chrome network tools

soulgalore commented 4 years ago

@taylorfinnell can you share a trace where that happens, then I can have a look and see how we could do it?

mikedijkstra commented 4 years ago

👋 I came across this while looking into an issue we were having.

I've created a reproducible case where a video is missing from the generated HAR because of a Network.loadingFailed event which removes the entry from the entries array.

How to reproduce

  1. Generate a devtools log for this URL: https://zfh61.csb.app/ See devtools log
  2. Generate a HAR using the devtools log See HAR

Logging the request IDs you can see the following:

URL: https://www.w3schools.com/tags/movie.mp4
16014.11 Network.requestWillBeSent
16014.11 Network.requestWillBeSentExtraInfo
16014.11 Network.responseReceivedExtraInfo
16014.11 Network.responseReceived
16014.11 Network.dataReceived
16014.11 Network.dataReceived
16014.11 Network.dataReceived
16014.11 Network.dataReceived
16014.11 Network.dataReceived
16014.11 Network.loadingFailed
16014.16 Network.requestWillBeSent
16014.16 Network.responseReceivedExtraInfo
16014.16 Network.responseReceived
16014.16 Network.dataReceived
16014.16 Network.loadingFailed

It looks to me like a possible solution would be to check if the event has received a response or data and only removing events which fail straight away. I'd be happy to help via a PR.

soulgalore commented 4 years ago

@mikedijkstra ah cool, yes a PR would be great! I'm wondering how we should represent the response in the HAR file?

mikedijkstra commented 4 years ago

@soulgalore Chrome shows the request up to the point where it was canceled, so I believe we can do the same by keeping the event around if it was canceled.