sitespeedio / chrome-har

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

Advice on capturing iframe or service worker events? #63

Closed sb8244 closed 4 years ago

sb8244 commented 4 years ago

Hi, I'm not sure of the best place to ask this. I see that there are some PRs / issues around iframe support in the project, but I'm struggling to see how to hook it up.

I am using the Chrome Extension debugger API to attach to the top level tabId. I then receive a top level iframe loading network event, but I won't receive any events for scripts inside of that iframe. The same thing occurs for service workers.

I think that I can manually attach to the iframe as a target, but that leaves the problem of attaching immediately and enabling network before any requests are made in the target. Target.setAutoAttach comes back successful, but I only see events the time after I restart the debugger—which is not super helpful. Using functions like Target.setDiscoverTargets just says "not allowed", so those don't seem viable.

Any pointers here?

soulgalore commented 4 years ago

Hi @sb8244 no sorry I have no idea.

sb8244 commented 4 years ago

No problem!

My research here is that it's generally not possible because Chrome doesn't provide a way to attach early enough to a target to capture every network event. There's no documentation on it at all, but I'm seeing the target attachment fail if attached sooner than 100ms after the page starts loading.

My current plan is to switch HAR generation tactics from the debugger to chrome devtools panel.

My stackoverflow comment if anyone has any other ideas: https://stackoverflow.com/questions/61512722/how-can-i-receive-events-for-an-embedded-iframe-using-chrome-devtools-protocol

sb8244 commented 4 years ago

I will close this out since there's nothing for the library here! Cheers.