Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture tracing information for all iframes #8991

Open
goelayu opened this issue Sep 21, 2022 · 8 comments
Open

Capture tracing information for all iframes #8991

goelayu opened this issue Sep 21, 2022 · 8 comments

Comments

@goelayu
Copy link

goelayu commented Sep 21, 2022

By default, page.tracing only captures the trace logs for the main frame. However, in Chrome's GUI when you capture the trace information, it by default captures it for all frames.

Is there a way to do the same programmatically?

The only way I can think of, is as follows:

  1. Using frameattached event, get access to every frame on the page
  2. Access the CDP client using frame._client API since it doesn't directly export the page object corresponding to each frame.
  3. Using this CDP client turn tracing on for each frame (cdp.send('Tracing.start'))
  4. Finally once all the frames are loaded, using the CDP client for each frame, turn tracing off and capture the tracing data.

Despite the above round about way, each frame will have its own trace file, as opposed to a single trace file containing information for all frames.

@OrKoN
Copy link
Collaborator

OrKoN commented Sep 21, 2022

@goelayu yes, I believe CDP clients have to enable tracing per target, i.e., frame or page and I am not sure if there is a workaround.

@goelayu
Copy link
Author

goelayu commented Sep 21, 2022

@OrKoN This might be orthogonal to this issue, but could you elaborate why page.setRequestInterception intercepts network requests across all frames, without having to do it per target, whereas page.tracing doesn't?

Also, if that is indeed the case, is this something that could be added in the future versions of this library, for consistency reasons?

@OrKoN
Copy link
Collaborator

OrKoN commented Sep 21, 2022

@goelayu not sure, maybe it works because it's happening in the network process. In general, the difficulty here is to merge different trace files together on Puppeteer side or make https://chromedevtools.github.io/devtools-protocol/tot/Tracing/#method-start cross-target.

@goelayu
Copy link
Author

goelayu commented Sep 22, 2022

@OrKoN So I tried the above described approach, and turns out the CDP client for each frame frame._client, points to the main page's CDP client, ie page._client.

To start tracing on each frame, I would need a way to create a CDP Session for each frame.
Any suggestions on how to go about doing that?

@OrKoN
Copy link
Collaborator

OrKoN commented Sep 23, 2022

There are two kinds of iframes: same-process and out-of-process. If the client is the same as the page client, it means the iframe is local and lives in the same renderer. In general, I would expect tracing to work for local iframes but not for out-of-process iframes. How do you determine that events are only captured for the main frame? The code starting the tracing is here https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/protocol/tracing_handler.cc;l=826;drc=f97e7e130b02a0fee5a06aa9cdf25d3a0a3715d0 but I am not 100% sure about the scope of tracing.

@goelayu
Copy link
Author

goelayu commented Sep 26, 2022

@OrKoN Thanks for the clarification. One follow-up question:
What determines when a given frame would be out-of-process or not? I was under the assumption that a frame loading a site from a different domain gets its own process. But based on the CDP clients, turns out all frames for a handful of pages I have tested this on, belong to the same process.

Regarding how I determine that events are only captured for the main frame, I upload the file to Chrome's Performance tab, and only a single frame's trace is displayed.
Also, when I parse the tracing data using lighthouse, I see the same result -- events from the main frame.

@fjh1997
Copy link

fjh1997 commented Mar 29, 2023

It seems work only when headless mode is disabled by default,And I find out it is about “Site Isolation”. Add --site-per-process to make it work in headless mode .

 const browser = await puppeteer.launch({
    args: ['--site-per-process'],
  })

@kaliiiiiiiiii
Copy link

@OrKoN Thanks for the clarification. One follow-up question: What determines when a given frame would be out-of-process or not? I was under the assumption that a frame loading a site from a different domain gets its own process. But based on the CDP clients, turns out all frames for a handful of pages I have tested this on, belong to the same process.

Regarding how I determine that events are only captured for the main frame, I upload the file to Chrome's Performance tab, and only a single frame's trace is displayed. Also, when I parse the tracing data using lighthouse, I see the same result -- events from the main frame.

related to #2548
Chromium design document https://www.chromium.org/developers/design-documents/oop-iframes/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants