Intercepting requests from iframes

1 261 wyświetleń
Przejdź do pierwszej nieodczytanej wiadomości

Jose Maria Rodriguez

nieprzeczytany,
25 paź 2019, 10:00:2025.10.2019
do Chromium Extensions

Hello,

TLDR; Is there any simple example code to capture requests done from iframes loaded from third domains?

I'm trying to intercept network requests, including those made from iframes running in different processes (CDP), using chrome.debugger.
For that, i'm using a simple page (residing in domain TEST_A.com, that simply loads an iframe from domain TEST_B.com , which contains a <script src..> tag.
As expected, without doing anything more, i can intercept the request and response to TEST_A.com, and the request to TEST_B.com . The network request for the script tag is not visible.

When i run my extension, i attach the debuuger all the targets (chrome.debugger.getTargets), and i get Target.attachedToTarget events from them, and set them to autoattach:

chrome.debugger.sendCommand(dd,'Target.setAutoAttach',{waitForDebuggerOnStart:true,autoAttach:true,flatten:true},function(){....});

As the test page is already loaded, i dont get any request calls, so i have to reload the test page.

Then:
 
  - The reloaded page  dont fire any attachedToTarget events, either from the top frame (which is still the same, as the target id is the same after the page reload), but i dont get any event for the iframe, so i cant attach the debugger to it waiting for this event.

 - If i open a new tab, and load another page, still i dont get any attachedToTarget events. I guess it's because is a new tab. But, somehow, it's the same case than the iframe: there's a new process i could attach to, and i'd like to auto-attach to it, or, at least, be notified that there is another target, so i can manually attach the debugger to it.

- There are events in the chrome debugger API (Target.targetCreated, Target.targetDestroyed, etc) which i never receive.So, the only  events i ever get are those marked as "experimental" (attachedToTarget,detachedFromTarget) , and only when the extension is initally fired.

- If i understand well, one of the possible targets is the browser itself (Target.attachToBrowserTarget). Calling this, i get a "Not allowed" error.

- If i call Target.setDiscoverTargets , i get "Not allowed" errors too.

- I can wait Frame related events, to attach to the iframe (as the id required for the chrome.debugger calls is the frameId).But if i call chrome.debugger.attach in that moment, i get a "Target doesnt exist" error.

Making the following changes, i can capture the network request associated to the javascript inside the iframe:

  - Modify the page loaded by the iframe, so the script is loaded after a 3 secs timeout.
  - Modify my extension, so after i receive a Frame.navigated event, and after a 1 sec timeout, i call chrome.debugger.attach to that iframe.

So somewhere between the Frame.navigated event, and 1 second later, the target was available to attach to, but, looking at all the received events after Frame.navigated, i dont see anything i could relate to the target.

So, how can i detect a new iframe has been created, and attach to it, possibly without losing any information (requests, script execution, etc)?

  

Odpowiedz wszystkim
Odpowiedz autorowi
Przekaż
Nowe wiadomości: 0