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: always use MainResource for main document #13756

Merged
merged 10 commits into from
Mar 22, 2022
Merged

Conversation

adamraine
Copy link
Member

@adamraine adamraine commented Mar 17, 2022

This PR aims to use the MainResource computed artifact universally instead of calling NetworkAnalyzer.findMainDocument directly. There are two reasons we would want to do this:

  • With Distinguish Navigation URLs and Frame URLs #13706, we would need to assert that the main document URL exists before every usage of NetworkAnalyzer.findMainDocument. If we use MainResource universally, we will only need to assert the main document URL exists within MainResource.
  • NetworkAnalyzer.findMainDocument will return the first document request if it is not given a URL as its second parameter. This will return an incorrect network request if there was a JS redirect. There are a few places where this can be confusing/problematic. See Improve handling of redirects, navStart #8984.

@adamraine adamraine requested a review from a team as a code owner March 17, 2022 20:43
@adamraine adamraine requested review from connorjclark and removed request for a team March 17, 2022 20:43
@@ -394,6 +394,8 @@ class PageDependencyGraph {
const networkNodeOutput = PageDependencyGraph.getNetworkNodeOutput(networkRecords);
const cpuNodes = PageDependencyGraph.getCPUNodes(processedTrace);

// TODO: Remove this usage of `findMainDocument`. This assumption isn't true if there was a JS redirect.
// ...
Copy link
Member Author

Choose a reason for hiding this comment

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

This file seems to depend mainDocumentRequest actually being the "first document request" in the case of a JS redirect. It might require a larger refactor in a different PR to eliminate the usage of NetworkAnalyzer.findMainDocument here.

@@ -7,11 +7,10 @@

/**
* @param {LH.Artifacts.NetworkRequest[]} networkRecords
* @param {LH.Artifacts.Script|undefined} script
Copy link
Member Author

Choose a reason for hiding this comment

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

Drive-by

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.

3 participants