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: add path property to script elements artifact #8133

Merged
merged 4 commits into from
Apr 13, 2019

Conversation

mattzeunert
Copy link
Contributor

Summary

When displaying JSON-LD script elements in DevTools we want to link them to the Elements panel, so we need to collect the node path to do that.

I saw the ScriptElements PR also updated lighthouse-core/test/results/artifacts/artifacts.json, but I'm not sure how that's updated...

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

nice find we should probably do this for the other *Elements artifacts sometime!

I updated the artifacts by running yarn update:sample-artifacts and then undoing all the changes it made other than ScriptElements, it's somewhat tedious work unfortch

@@ -9,6 +9,9 @@ const Gatherer = require('./gatherer.js');
const NetworkAnalyzer = require('../../lib/dependency-graph/simulator/network-analyzer.js');
const NetworkRequest = require('../../lib/network-request.js');
const getElementsInDocumentString = require('../../lib/page-functions.js').getElementsInDocumentString; // eslint-disable-line max-len
const pageFunctions = require('../../lib/page-functions.js');

/* global getNodePath */

/**
* @return {LH.Artifacts['ScriptElements']}
Copy link
Collaborator

Choose a reason for hiding this comment

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

we need to update the types too

@@ -26,6 +29,8 @@ function collectAllScriptElements() {
async: script.async,
defer: script.defer,
source: /** @type {'head'|'body'} */ (script.closest('head') ? 'head' : 'body'),
// @ts-ignore - getNodePath put into scope via stringification
path: getNodePath(script),
Copy link
Collaborator

Choose a reason for hiding this comment

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

path might be a tad too generic on the *Elements artifacts for my taste, given it's basically a devtools-specific crazy node child index array

WDYT about...

devtoolsNodePath
devtoolsChildIndexNodePath
nodePathForDevToolsRevealing

any other suggestions welcome :)

Copy link
Contributor Author

@mattzeunert mattzeunert Apr 10, 2019

Choose a reason for hiding this comment

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

nodeReferencePath? I'd like to avoid tying it to DevTools, since other consumers could theoretically use it too. Unless we strongly think they shouldn't.

So for now we'd use the new name here and keep path everywhere else?

Copy link
Collaborator

Choose a reason for hiding this comment

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

since other consumers could theoretically use it too

😱 I hope not!

😆 If you can't tell, I'm not fond of this particular path approach, so I would prefer to limit its scope and push a more flexible strategy that can be resilient to reloads.

So for now we'd use the new name here and keep path everywhere else?

yeah just thinking out loud here. I've proposed to only expose the *Elements artifacts as the public API for v5 so I'm thinking of them quite separately from the others at this point, which might not align with the rest of LH team yet :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to limit its scope and push a more flexible strategy that can be resilient to reloads.

#2289 (comment) fyi

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @hoten I'm glad we've already made some awesome improvements here :D

To clarify, my main goal if we're exposing this to plugin consumers in *Elements would be to provide a path that has some value even when the node cannot be found, i.e. based on some sort of identifiers/classes/etc on the page and not just child indexes that don't provide much value to a human, some selector/path hybrid I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😱 I hope not!

Ok, __legacyDevToolsPathDontUseEver it is then 😂

some selector/path hybrid I guess

Were you thinking of the selector property we show currently when the user hovers over a node in the report?

Axe already aims to make that a unique selector. getNodeSelector generates selectors based on the id/class name if available, but doesn't attempt to make that unique.

Seems like we don't need path at all if we can make selector unique.

Copy link
Collaborator

Choose a reason for hiding this comment

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

__legacyDevToolsPathDontUseEver 😍 love it! 😆

I don't want to hold things up on this, but I'm just afraid of what we won't be able to take back once 5.0 hits :)

Anyone else core have thoughts on our public artifacts API? I think I might stir up this convo over on the issue...

Copy link
Member

Choose a reason for hiding this comment

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

devtoolsNodePath sounds great to me, personally. Sounds uninvitingly opaque if you aren't devtools, you still know exactly what it is, and even if you do figure out how to use it, it sounds like the gears of devtools turning could change the format at any time.

Also fine with a leading underscore (but I vote we stay away from two :) and a strongly worded comment, but I think that's more than enough at that point.

Copy link
Member

Choose a reason for hiding this comment

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

@paulirish if he has an opinion

Copy link
Member

Choose a reason for hiding this comment

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

fine with devtoolsNodePath. seems cool.

Here's where the protocol uses it: https://vanilla.aslushnikov.com/?DOM.pushNodeByPathToFrontend

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM!

@patrickhulce
Copy link
Collaborator

travis is harder to please though :) I think you'll have to provide an empty one for the network-discovered scripts

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM2

@brendankenny brendankenny merged commit c5143c1 into master Apr 13, 2019
@brendankenny brendankenny deleted the add-path-to-script-elements branch April 13, 2019 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants