3

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:

  1. A tab is loaded
  2. Inject chrome debugger into tab
  3. Call Network.enable to ensure that any network messages will be received (since there's no retroactive logging)
  4. Reload the tab via extension API
  5. onDOMContentLoaded -> enable all APIs via protocol (Log, Performance, Runtime) and set Target.setAutoAttach
  6. 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.

sb8244
  • 152
  • 10
  • 1
    Assuming you also do the [rest of the required motions](https://crbug.com/924937#c13) this seems to be the correct approach. – wOxxOm Apr 30 '20 at 05:27
  • I had thought the same, but I'm not receiving the attach event until the second time I attach the debugger. And in that case I receive attach/detach immediately. Thanks for this link. – sb8244 May 01 '20 at 01:22
  • I think that it may actually be an artifact of using https://htmledit.squarefree.com/ for my tests. If I attach to that page and add an iframe, I do not get attached events. If I use my hosted example (like a normal webpage), then I get target attached events. I will experiment with it on my hosted example rather than using the squarefree HTML editor. – sb8244 May 01 '20 at 01:28
  • I have added more context to the question--including my invocation flow – sb8244 May 01 '20 at 03:16
  • This might be a known issue. https://groups.google.com/forum/#!topic/chrome-debugging-protocol/n1FQ4Ypww6w documents that it can't attach early and may go away anyways (experimental) – sb8244 May 01 '20 at 03:35

0 Answers0