I am attempting to use Chrome Devtools Protocol to list the network and log events for a tab. I am successful in doing so for the top level frame, but am struggling with children iframes.
When I have an iframe that is the same domain as the parent, it captures network and log events properly. When I have an iframe that is on a different domain, it doesn't emit any events at all.
I've tried to set auto attachment via
chrome.debugger.sendCommand({ tabId: tabId }, "Target.setAutoAttach", { autoAttach: true, waitForDebuggerOnStart: false, flatten: true })
but this doesn't seem to do anything for me. How can I properly inspect the network and log events of the iframe under an actively debugged tab?
Here's my current flow with setAutoAttach:
- A tab is loaded
- Inject chrome debugger into tab
- Call Network.enable to ensure that any network messages will be received (since there's no retroactive logging)
- Reload the tab via extension API
- onDOMContentLoaded -> enable all APIs via protocol (Log, Performance, Runtime) and set Target.setAutoAttach
- Process messages
If I do this flow, I get no attached events. If I setAutoAttach at point 2--before reload--then I get the PREVIOUS instance's iframe. I can only get the current tab's iframes after completely detaching the debugger, reattaching, and then calling setAutoAttach. Calling setAutoAttach
in a timeout of 1 second also ends up giving me the attached tabs, but then it's too late to capture network traffic.