sitespeedio / chrome-har

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

Early hints requests do not appear in HAR #115

Closed benschwarz closed 1 month ago

benschwarz commented 2 months ago

On a page with verified early hints requests we can see requests initiated by early hints:

image

Running that page with npx browsertime --chrome.collectPerfLog -n 1 $URL and inspecting the HAR we can see:

Inspecting the devtools log I can see that the request made to master-cb9e9afd3d.css (request ID: 87395.8) has the expected Network.requestWillBeSent, Network.responseReceived, Network.dataReceived, Network.loadingFinished events.

Curiously, I noticed that both fromDiskCache and fromEarlyHints are both true on the Network.responseReceived request:

image

In checking entryFromResponse.js we can see that fromDiskCache and __servedFromCache are used to gate functionality:

https://github.com/sitespeedio/chrome-har/blob/2006c4dce0971180b023dda3fe7c0cd085efeadf/lib/entryFromResponse.js#L93

https://github.com/sitespeedio/chrome-har/blob/2006c4dce0971180b023dda3fe7c0cd085efeadf/lib/entryFromResponse.js#L180

I suspect we'll want to check request entries to see if they've been loaded by early request hints.

In case we need it, there's a Network.responseReceivedEarlyHints event.

benschwarz commented 2 months ago

It's late where I am now, I'll prepare a fix tomorrow during my day.

soulgalore commented 2 months ago

Thank you @benschwarz for creating the issue. Let me know If you need some help!

soulgalore commented 2 months ago

@benschwarz I made a PR that maybe fixes it, if you have please check if it works for you :)

benschwarz commented 2 months ago

Hey @soulgalore, apologies for the delay. I'll be wrapped up in something else until next week. I suspect your fix is all that's required, but I want to first check if there's any strange side effects and update the test suite so that it's covered in future.

soulgalore commented 2 months ago

I think that should be safe. We could add a test example, I can do that later on.