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

core: resolve redirected script records #13751

Merged
merged 6 commits into from
Mar 17, 2022
Merged

core: resolve redirected script records #13751

merged 6 commits into from
Mar 17, 2022

Conversation

adamraine
Copy link
Member

Fixes #13724

@adamraine adamraine requested a review from a team as a code owner March 16, 2022 17:10
@adamraine adamraine requested review from connorjclark and removed request for a team March 16, 2022 17:10
@@ -372,11 +372,8 @@ class LegacyJavascript extends ByteEfficiencyAudit {
let transferRatio = transferRatioByUrl.get(url);
if (transferRatio !== undefined) return transferRatio;

const mainDocumentRecord = NetworkAnalyzer.findOptionalMainDocument(networkRecords);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using findOptionalMainDocument without specifying a URL will just find the first document request. This isn't necessarily the main document if there was a redirect though.

I think it makes more sense to just get the main document record using the script URL like any other script in this case. For timespan/snapshot, finalUrl isn't necessarily the main document URL either #13706.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup! and this would very much be a bug for inline scripts in iframes. not sure why we (Read: I) did it this way 🤔

const networkRecord = url === artifacts.URL.finalUrl ?
mainDocumentRecord :
networkRecords.find(n => n.url === url);
const networkRecord = getRequestForScript(networkRecords, script);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could const url be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still used in multiple places, I think we can leave it.

@@ -372,11 +372,8 @@ class LegacyJavascript extends ByteEfficiencyAudit {
let transferRatio = transferRatioByUrl.get(url);
if (transferRatio !== undefined) return transferRatio;

const mainDocumentRecord = NetworkAnalyzer.findOptionalMainDocument(networkRecords);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup! and this would very much be a bug for inline scripts in iframes. not sure why we (Read: I) did it this way 🤔

lighthouse-core/lib/script-helpers.js Outdated Show resolved Hide resolved
@connorjclark connorjclark changed the title core(scripts): resolve redirected script records core: resolve redirected script records Mar 16, 2022
@adamraine adamraine merged commit 9847c11 into master Mar 17, 2022
@adamraine adamraine deleted the redirected-scripts branch March 17, 2022 20:02
connorjclark pushed a commit that referenced this pull request May 10, 2022
9.6.0 note: Added `fakeScript` var to places to make up for the fact
that this release does not have "Scripts" refactor.
This was referenced May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect transfer size for redirected script URL
3 participants