Skip to content

core: add finalDisplayedUrl, mainDocumentUrl to LHR. deprecate finalUrl#14149

Merged
adamraine merged 42 commits into
mainfrom
final-page-url
Oct 4, 2022
Merged

core: add finalDisplayedUrl, mainDocumentUrl to LHR. deprecate finalUrl#14149
adamraine merged 42 commits into
mainfrom
final-page-url

Conversation

@adamraine

@adamraine adamraine commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Alternative to #13819 that keeps finalUrl on the LHR

This also deprecates the currently unnecessary artifacts.URL.initialUrl

Closes #13706

@adamraine adamraine changed the title WIP: add finalPageUrl, deprecate finalUrl core: add finalPageUrl, deprecate finalUrl Jul 6, 2022
@adamraine adamraine marked this pull request as ready for review July 6, 2022 17:52
@adamraine adamraine requested a review from a team as a code owner July 6, 2022 17:52
@adamraine adamraine requested review from brendankenny and removed request for a team July 6, 2022 17:52
Comment thread lighthouse-core/runner.js Outdated
Comment thread types/lhr/lhr.d.ts
Comment on lines +18 to +19
/** URL of the last document request during a Lighthouse navigation. Will be `undefined` in timespan/snapshot. */
mainDocumentUrl?: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This turns out to be a pretty unfortunate bifurcation in practice.

For navigations, finalDisplayedUrl really isn't useful for almost anything except displaying at the top of the final report. In practice it doesn't matter many times (it has to be the same origin as mainDocumentUrl and a lot of our uses of it are same-origin checks), but it does allow keeping a standardized "use the main document" as the reference for everything.

Splitting between uses of mainDocumentUrl and the displayed url breaks that a bit, and makes it so you have to spend longer on code thinking, which URL do I need to use? But mainDocumentUrl doesn't exist for timespans/snapshots.

But...could it exist? Surely there's some way of retrieving that information. TracingStartedInBrowser event in traces? The frame tree somewhere? Page.getNavigationHistory or whatever?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But...could it exist? Surely there's some way of retrieving that information. TracingStartedInBrowser event in traces? The frame tree somewhere? Page.getNavigationHistory or whatever?

Believe me when I tell you that I have tried:

  • TracingStartedInBrowser: Not available in snapshot mode
  • The frame tree: Always the frame/displayed url
  • Page.getNavigationHistory: I forget the details but hit a roadblock with 300 redirects

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Even if we could get mainDocumentUrl for timespan, would it represent the main document at the start or at the end?

TBH we may not need to include mainDocumentUrl on the LHR. finalUrl is the exact same thing in its deprecated state for historical reasons but we don't actually use either from what I can tell.

@brendankenny brendankenny Aug 9, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Even if we could get mainDocumentUrl for timespan, would it represent the main document at the start or at the end?

Absolutely a good point but functionally equivalent to if it makes sense for e.g. third-party-summary's mainEntity to be based on finalDisplayedUrl, so it doesn't really matter for this. The answer to that is going to have to come out of some deeper decision(s).

edit: we still have time to switch it to finalMainDocumentUrl :P

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TBH we may not need to include mainDocumentUrl on the LHR. finalUrl is the exact same thing in its deprecated state for historical reasons but we don't actually use either from what I can tell.

@brendankenny what do you think about removing mainDocumentUrl from the lhr but keeping finalUrl?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

adam, can you update the PR title to reflect the current state?

seems like it's

add finalDisplayedUrl,mainDocumentUrl to LHR. deprecate finalUrl.

removing initialUrl from artifacts seems minor in comparison but i'd call it out in the initial summary.


@brendankenny what do you think about removing mainDocumentUrl from the lhr but keeping finalUrl?

The argument against that is that the name finalUrl is ambiguous. And that's why mainDocumentUrl is the new name of it. adding a final- prefix isn't needed for navigation, but does make sense for timespan, as there could be multiple.


But mainDocumentUrl doesn't exist for timespans/snapshots.
But...could it exist? Surely there's some way of retrieving that information.

performance.getEntriesByType('navigation')[0].name

This has it. It also includes the hash fragment, but that's easily strippable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removing initialUrl from artifacts seems minor in comparison but i'd call it out in the initial summary.

Sounds good.

The argument against that is that the name finalUrl is ambiguous. And that's why mainDocumentUrl is the new name of it. adding a final- prefix isn't needed for navigation, but does make sense for timespan, as there could be multiple.

I just don't think it makes sense to call out a singular mainDocumentUrl in timespan mode. I could see us creating a list of main document urls for something like 3P analysis, but we will never need just the last one for timespan mode.

This has it. It also includes the hash fragment, but that's easily strippable.

This looks promising. I'm still hesitant to use it in timespan mode for the reasons above, but this could work for snapshot mode. I would do this in a follow-up PR since we don't have a use for it yet.

Comment thread viewer/app/src/github-api.js Outdated
Comment thread report/generator/file-namer.js Outdated
@adamraine

Copy link
Copy Markdown
Contributor Author

copybara-service Bot pushed a commit to ChromeDevTools/devtools-frontend that referenced this pull request Sep 22, 2022
Ensures DT is compatible with this change:
GoogleChrome/lighthouse#14149

Bug: None
Change-Id: Ic77a048f56f030499ba5d4db4a0ee41241e8ea65
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3911354
Commit-Queue: Adam Raine <asraine@chromium.org>
Reviewed-by: Connor Clark <cjamcl@chromium.org>
@adamraine adamraine changed the title core: add finalDisplayedUrl, deprecate finalUrl, remove initialUrl core: add finalDisplayedUrl, mainDocumentUrl to LHR. deprecate finalUrl` Sep 27, 2022
@adamraine adamraine changed the title core: add finalDisplayedUrl, mainDocumentUrl to LHR. deprecate finalUrl` core: add finalDisplayedUrl, mainDocumentUrl to LHR. deprecate finalUrl Sep 27, 2022

@connorjclark connorjclark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

calling out this for follow-up

This looks promising. I'm still hesitant to use it in timespan mode for the reasons above, but this could work for snapshot mode. I would do this in a follow-up PR since we don't have a use for it yet.

@adamraine adamraine merged commit cd1ee88 into main Oct 4, 2022
@adamraine adamraine deleted the final-page-url branch October 4, 2022 19:57
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.

Distinguish Navigation URLs and Frame URLs

6 participants