lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Lighthouse doesn't listen to network events on worker targets

Open adamraine opened this issue 3 years ago • 2 comments

The following issue is caused by Lighthouse ignoring targets of type worker:

https://github.com/GoogleChrome/lighthouse/blob/d13a91961b63885031acaa1a3e4ad36fd0376c03/lighthouse-cli/test/smokehouse/test-definitions/oopif-scripts.js#L69-L75

This is a simple fix for legacy driver, we just treat worker targets the same as iframe here: https://github.com/GoogleChrome/lighthouse/blob/d13a91961b63885031acaa1a3e4ad36fd0376c03/lighthouse-core/gather/driver.js#L299

Unfortunately, things get dicey in FR mode. Puppeteer doesn't give us the target info on 'sessionattached' events so we normally call Target.getTargetInfo on the session puppeteer gives us. However, Target.getTargetInfo isn't allowed (throws an error) for worker targets which is a bug according to @caseq.

https://bugs.chromium.org/p/chromium/issues/detail?id=1344293

Ideally we will have Target.getTargetInfo working on all targets and add worker to the list of important target types.

adamraine avatar Jul 13 '22 22:07 adamraine

Honestly I haven't figured out why this is working in DevTools in the first place.

adamraine avatar Jul 13 '22 22:07 adamraine

Update: pausing workers doesn't work the same way as pausing frames:

Screen Shot 2022-07-18 at 4 45 23 PM

Links: https://gist.github.com/adamraine/3cc8ac108ff1667cad8d10c994cd317b https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/common/features.cc;drc=97f94c6631e327c2c1a9891774b44fbba9e8e3bf;l=201

adamraine avatar Jul 18 '22 23:07 adamraine

There are actually 2 upstream issues blocking this I guess: https://bugs.chromium.org/p/chromium/issues/detail?id=1352175

adamraine avatar Aug 11 '22 16:08 adamraine

Both crbugs are resolved on ToT now. Should be pretty simple to fix this now, but we should wait until the changes reach stable.

adamraine avatar Nov 29 '22 22:11 adamraine

Both fixes have landed in stable (M110) so we should consider attaching to worker targets now.

adamraine avatar Mar 07 '23 19:03 adamraine

Seems good, though like iframes, the impact isn't entirely clear outside of simple stuff like bytes downloaded. e.g. is it bad for performance if nytimes downloads 10 MiB in a worker?

Lantern will calculate network contention (assuming it gets the timing right...might need an explicit worker creation node since it won't have a network root like an iframe does?), but will there be any other effect except as bandwidth sinks?

brendankenny avatar Mar 07 '23 19:03 brendankenny

How are worker network protocol messages differentiated from the page's? Do they share a frameId and for same-frame checks should we also be looking at sessionId or something else?

brendankenny avatar Mar 07 '23 19:03 brendankenny

For the frameId/sessionId/source question, should consider implementing alongside https://github.com/GoogleChrome/lighthouse/issues/14157 so we have explicit target information per request

brendankenny avatar Mar 07 '23 20:03 brendankenny

is it bad for performance if nytimes downloads 10 MiB in a worker?

It's certainly not good, and I think we should be reporting the complete network story either way.

but will there be any other effect except as bandwidth sinks?

I would expect bandwidth sinks to be the primary concern. Workers always run in a separate thread.

How are worker network protocol messages differentiated from the page's? Do they share a frameId and for same-frame checks should we also be looking at sessionId or something else?

There are a couple ways to identify them on the Network.requestWillBeSent event:

  • loaderId will be an empty string
  • frameId will be undefined

adamraine avatar Mar 08 '23 23:03 adamraine

I was testing https://github.com/GoogleChrome/lighthouse/pull/14212, and ran into issues for Lighthouse in DevTools, looks like it's another Chrome bug:

https://bugs.chromium.org/p/chromium/issues/detail?id=1423096

adamraine avatar Mar 09 '23 20:03 adamraine