GoogleChrome / lighthouse

Automated auditing, performance metrics, and best practices for the web.
https://developer.chrome.com/docs/lighthouse/overview/
Apache License 2.0
28.05k stars 9.32k forks source link

Gathering trace data from iframe targets #15846

Closed rggammon closed 4 months ago

rggammon commented 4 months ago

FAQ

URL

https://github.com/puppeteer/puppeteer/issues/8991

What happened?

I am working with a site that uses cross-domain iframes, and notice that when I load a trace gathered by lighthouse into the devtools timeline/profiler viewer, I don't see data for the iframe. eg: js sample data, w/ https://github.com/GoogleChrome/lighthouse/pull/15542

What did you expect?

I'd like to see trace data for cross-domain iframes

What have you tried?

There is some discussion of this in https://github.com/puppeteer/puppeteer/issues/8991

My hypothesis based on https://github.com/puppeteer/puppeteer/issues/8991 would be that tracing needs to be enabled on these iframe targets as they are attached, similar to how Network.enable is being called per-session on attach - https://github.com/GoogleChrome/lighthouse/blob/912495d95e8d81a5ef94ba37ffbed9bc54536d1a/core/gather/driver/target-manager.js#L162

And then, I think with flat protocol mode, traces for all the targets would have sessionId's and it is possible to merge all the trace events in one json file and devtools can load this combined file and show all frames in timeline/profile view.

How were you running Lighthouse?

node

Lighthouse Version

11.5.0

Chrome Version

No response

Node Version

No response

OS

Linux

Relevant log output

No response

adamraine commented 4 months ago

I am seeing information for cross-origin iframes in traces collected by Lighthouse. For example:

https://trace.cafe/t/YgqEQVRVS9

This page contains several iframes and the data for each frame is present in the trace. I got the trace by running the following command:

lighthouse https://www.paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/ -G

Then I loaded latest-run/defaultPass.trace.json into a trace viewer (in this case trace.cafe but the DevTools performance panel is the same).

Maybe I'm misunderstanding something. What steps can I take to reproduce what you are seeing?

rggammon commented 4 months ago

Thank you for the cli pointer - indeed it is working for me there. Here is a trace of paulirish.com with my setup where I don't see the iframes - https://trace.cafe/t/ZJoILNJNJX

Given that it is working with the cli, I should be able to compare my setup to this, and can report back with what the issue was.

adamraine commented 4 months ago

@rggammon are you launching Chrome in old headless mode? I believe this was the default when using Puppeteer before Puppeteer v22.x.

In old headless mode, OOPIFs are disabled and so iframe thread activity will appear on the main thread.

If this is the case, using the new headless mode should be enough to fix the issue.

rggammon commented 4 months ago

@adamraine I am actually launching chrome via playwright launchPersistentContext with headless: true - which is likely the issue. Thank you for the pointer! Will figure out how to get launchPersistentContext using new headless mode, and can post that here & resolve this

rggammon commented 4 months ago

My issue wasn't with lighthouse but with how it is getting run -

Closing the bug, thank you again for the pointers!