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(fps): make lhId less dependent on chrome internals #14272

Merged
merged 12 commits into from
Aug 16, 2022
Merged

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Aug 9, 2022

The specific id for the execution context varies as Chrome internals does different work before we even begin Lighthouse gathering, and has already changed twice recently. Instead of using the exact id value, instead log the context ids we've used and use the indexOf from that array as the new execution-context specific position of the lhId.

These values should now only depend on the order in which we run our code (or whatever variance exists on the page that changes what elements our code inspects).

@connorjclark connorjclark requested a review from a team as a code owner August 9, 2022 22:47
@connorjclark connorjclark requested review from brendankenny and removed request for a team August 9, 2022 22:47
* value (that doesn't expose the actual execution context id) to use for __lighthouseMainExecutionContextId.
* @type {number[]}
*/
this._executionContextIdentifiersUsed = [];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Initially I just did contextId - this._executionContextId, but this is problematic due to the existence of clearContextId.

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

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

This looks good. Do you want to revert back to the old smoke expectations to see how robust it is?

core/gather/driver/execution-context.js Show resolved Hide resolved
core/gather/driver/execution-context.js Outdated Show resolved Hide resolved
core/gather/driver/execution-context.js Outdated Show resolved Hide resolved
window.__lighthouseExecutionContextId !== undefined ?
window.__lighthouseExecutionContextId :
'page',
window.__lighthouseExecutionContextUniqueIdentifier ?? '?',
Copy link
Member

Choose a reason for hiding this comment

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

'page' wasn't super descriptive but it was something to denote the difference between isolated context elements and page-context. We could pick something else

@@ -498,6 +498,12 @@ function getNodeDetails(element) {
const selector = getNodeSelector(element);

// Create an id that will be unique across all execution contexts.
//
// Made up of 3 components:
// - number unique to specific execution context
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to document somewhere that we don't need this because we have multiple isolated contexts at the end of things, we just have the one. We only really need this number because some elements may have been saved by other gatherers in other execution contexts, and we need to be able to know they don't match any element saved by FPS because those contexts are long gone by the time FPS rolls around.

Functionally it's the same thing, but we currently make it sound more complicated than it really is (as if we're juggling multiple simultaneous isolated execution contexts).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But we do have multiple execution contexts - the page context and the optional isolated context.

Copy link
Member

Choose a reason for hiding this comment

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

Only the one isolated context. Equivalently, we only have one context ID at a time, including at the end of the run.

const uniqueExecutionContextIdentifier = contextId === undefined ?
0 :
this._executionContextIdentifiersCreated;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@brendankenny not sure if this is what you had in mind, but we need to be mindful of the "undefined"/"page" context here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, more or less, though I actually think the previous undefined (instead of 0) here is kind of cleaner--there is no isolated context for that case, it makes it clearer that it's separate from the numbering of the contexts, and it eliminates the need for the '?' case below.

@paulirish paulirish changed the title core(full-page-screenshot): make lhId less dependant on chrome internals core(full-page-screenshot): make lhId less dependent on chrome internals Aug 15, 2022
@connorjclark connorjclark changed the title core(full-page-screenshot): make lhId less dependent on chrome internals core(full-page-screenshot): make ids less dependent on chrome internals Aug 16, 2022
@connorjclark connorjclark changed the title core(full-page-screenshot): make ids less dependent on chrome internals core(full-page-screenshot): ids less dependent on chrome internals Aug 16, 2022
@connorjclark connorjclark changed the title core(full-page-screenshot): ids less dependent on chrome internals core(fps): make lhId less dependent on chrome internals Aug 16, 2022
@connorjclark connorjclark merged commit e9b8c47 into master Aug 16, 2022
@connorjclark connorjclark deleted the page-fn-id branch August 16, 2022 19:12
@brendankenny
Copy link
Member

Do you want to revert back to the old smoke expectations to see how robust it is?

did you end up trying this?

@connorjclark
Copy link
Collaborator Author

I did not because the new expectations seem better to me. No need to care about differences b/wn FR and legacy runners.

@brendankenny
Copy link
Member

Wasn't the point of this change that there shouldn't be any differences now?

@connorjclark
Copy link
Collaborator Author

connorjclark commented Aug 16, 2022

No-FR is gonna run gatherers in different order, right? Then the ids will be different.

point was to just prevent the dependence on chrome doing...whatever it was doing that resulted in multiple execution ids being created before LH starts.

@brendankenny
Copy link
Member

point was to just prevent the dependence on chrome doing...whatever it was doing that resulted in multiple execution ids being created before LH starts.

Which would have been tested by reverting. /[0-9]-[0-9]+-IMG/ passes with or without this PR.

alexnj pushed a commit to alexnj/lighthouse that referenced this pull request Aug 24, 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.

3 participants