GoogleChrome / GoogleChrome/lighthouse

Cleanup Network Handling in Gatherers

Open
#11,454 1 comment 0 reactions 0 assignees View on GitHub
internals needs-investigation P2
Dominant language
JavaScript
Stars
30.8k
Forks
9.8k
Avg merge
1d 14h
Merged PRs (30d)
20

Description

**Summary**
The root cause of https://github.com/GoogleChrome/lighthouse/issues/11450 was that we link up network records and image elements using `record.url === image.src` but this breaks down for images that redirected. I looked around and it seems like many, many audits might be susceptible to a similar pitfall.

A few more things that came to mind we should probably fix in this space...

- [ ] Extract a shared `findMatchingNetworkRecord` function that can handle this redirect logic, do the `*ByUrl` nonsense that we have duplicated everywhere, etc
- [x] Remove duplicated `resourceSize` in `ImageElements` that duplicates network record property (breaking change, ref https://github.com/GoogleChrome/lighthouse/issues/11207)
- [ ] Check the redirect URL reporting behavior of...
- [ ] ScriptElements
- [ ] CSSUsage
- [ ] JsUsage

i.e. when we create our map of URL -> network record we shouldn't just use URL, but also use..
```js
// Also index all of its redirect source.
let originalRequest = record;
while (originalRequest.redirectSource) originalRequest = originalRequest.redirectSource;
map[originalRequest.url] = record;
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the duplicated network-record URL matching and *ByUrl logic, then inspect the ScriptElements, CSSUsage, and JsUsage reporting paths. Verify how redirectSource chains are represented and where URL-to-record maps are built. Done means shared redirect-aware matching is used consistently and redirect URL behavior is checked for all three areas.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.