core(report): show nodeLabel for DOM nodes in addition to snippet#8961
Conversation
brendankenny
left a comment
There was a problem hiding this comment.
nice! Definitely helps give context better than the snippet alone. I wonder if there's more we could do to tie the new text and the snippet together visually, though
| @@ -213,6 +214,7 @@ module.exports = [ | |||
| '\n big enough target\n </a>', | |||
| 'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A', | |||
| 'selector': 'body > div > div > a', | |||
There was a problem hiding this comment.
can you add to the a11y expectations as well?
There was a problem hiding this comment.
Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.
There was a problem hiding this comment.
Added details.items assertions.
There was a problem hiding this comment.
Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.
haha, uh oh, I guess I didn't know how much I was asking for :) I guess we can just cross our fingers that these are stable and all worth testing. I do really like the extra coverage this gets us
There was a problem hiding this comment.
When @mattzeunert does something, he does it right, and you get the works! 😎
Removed some unnecessary margin between the two. Not sure what else to do exactly, @hwikyounglee any suggestions? |
Thanks Matt. Only thing I would double check is the contrast of the green text on gray and on white. We need to aim for 4.5 at minimum. @yuinchien for any further guidance |
brendankenny
left a comment
There was a problem hiding this comment.
this looks great. Last nits
| @@ -213,6 +214,7 @@ module.exports = [ | |||
| '\n big enough target\n </a>', | |||
| 'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A', | |||
| 'selector': 'body > div > div > a', | |||
There was a problem hiding this comment.
Right now all we assert there is { length: 1 }, but I'll change it when I do the final artifact update for this PR.
haha, uh oh, I guess I didn't know how much I was asking for :) I guess we can just cross our fingers that these are stable and all worth testing. I do really like the extra coverage this gets us
| function getNodeLabel(node) { | ||
| const tagName = node.tagName.toLowerCase(); | ||
| if (tagName !== 'html' && tagName !== 'body') { | ||
| const title = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label'); |
There was a problem hiding this comment.
not a big deal, but I guess s/title/label
| function getNodeLabel(node) { | ||
| const tagName = node.tagName.toLowerCase(); | ||
| if (tagName !== 'html' && tagName !== 'body') { | ||
| const title = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label'); |
There was a problem hiding this comment.
also should use the standard node.textContent (unless innerText was intentional?)
There was a problem hiding this comment.
I specifically requested innerText because textContent gets us all that inline script instead of actual text
| renderNode(item) { | ||
| const element = this._dom.createElement('span', 'lh-node'); | ||
| if (item.nodeLabel) { | ||
| const titleEl = this._dom.createElement('div'); |
| return parts.join(' > '); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
can you add a comment for this function? Basically trying to provide a human recognizable label for the given element. Falls back to the tagName if no useful label is found.
| /* istanbul ignore next */ | ||
| function getNodeLabel(node) { | ||
| const tagName = node.tagName.toLowerCase(); | ||
| if (tagName !== 'html' && tagName !== 'body') { |
There was a problem hiding this comment.
can you add back that comment about why we skip html and body
| if (title) { | ||
| return truncate(title, 80); | ||
| } else { | ||
| const nodeToUseForTitle = node.querySelector('[alt], [aria-label]'); |
There was a problem hiding this comment.
maybe add comment about why it's useful to recursively search (what cases does this help with?)
| --color-blue-200: #90CAF9; | ||
| --color-blue-900: #0D47A1; | ||
| --color-teal-300: #00d6c1; | ||
| --color-teal-700: #008577; |
There was a problem hiding this comment.
Re-introduced teal since it was a bit nicer than the green. Do the numbers at the end have a specific meaning, other than broadly identifying darkness?
There was a problem hiding this comment.
It's the shade in the material design color palette https://material.io/design/color/#
There was a problem hiding this comment.
is this the right number, then?
brendankenny
left a comment
There was a problem hiding this comment.
LGTM!
@patrickhulce do you want to take another look?
| --color-blue-200: #90CAF9; | ||
| --color-blue-900: #0D47A1; | ||
| --color-teal-300: #00d6c1; | ||
| --color-teal-700: #008577; |
There was a problem hiding this comment.
is this the right number, then?
patrickhulce
left a comment
There was a problem hiding this comment.
I don't love the truncate situation, but I won't block an otherwise approved merge because of it either.
I'll just pick "Comment" instead :)
LGTM otherwise!
| @@ -213,6 +214,7 @@ module.exports = [ | |||
| '\n big enough target\n </a>', | |||
| 'path': '2,HTML,1,BODY,3,DIV,21,DIV,1,A', | |||
| 'selector': 'body > div > div > a', | |||
There was a problem hiding this comment.
When @mattzeunert does something, he does it right, and you get the works! 😎
| if (tagName !== 'html' && tagName !== 'body') { | ||
| const nodeLabel = node.innerText || node.getAttribute('alt') || node.getAttribute('aria-label'); | ||
| if (nodeLabel) { | ||
| return truncate(nodeLabel, 80); |
There was a problem hiding this comment.
I was making this comment over in #8979 , but it's unfortunate when page-functions in a lib have dependencies on each other that you have to know about ahead of time.
since it's basically a single ternary line WDYT about copying the function definition in the two files instead?
There was a problem hiding this comment.
Are you thinking have it in tap-targets.js and also inlined inside getNodeLabel?
There was a problem hiding this comment.
Yeah that was my thought
| .lh-vars.dark { | ||
| --color-red-700: var(--color-red); | ||
| --color-green-700: var(--color-green); | ||
| --color-teal-600: var(--color-cyan-500); |
There was a problem hiding this comment.
dark mode is weird o.O
with this, tap-targets, iframeelements, and...other stuff(?) making changes to |
|
Maybe the exported |
…d a new element at the top of the page
Yeah that's a good idea, though perhaps dupes might be an issue then? Since the function is so simple here I think inline is decent option, but we'll have to figure this out long-term for sure either. |
Is there an issue with dupes other than aesthetics? There'd be a perf impact but that seems very minor. |
I was thinking of variable declarations not function declarations, but I suppose all our dupes would be of function declarations, so it's a non-issue. 👍 |
patrickhulce
left a comment
There was a problem hiding this comment.
LGTM! Thanks @mattzeunert for the fix! 🙏



Summary
Collect a human-readable title for each node and display it above the snippet.
Related Issues/PRs
#6683