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

Improve node selectors shown in the details table #4015

Closed
kdzwinel opened this issue Dec 8, 2017 · 2 comments
Closed

Improve node selectors shown in the details table #4015

kdzwinel opened this issue Dec 8, 2017 · 2 comments
Assignees

Comments

@kdzwinel
Copy link
Collaborator

kdzwinel commented Dec 8, 2017

In is-crawlable and hreflang audits nodes listed in the details table have no selector set eg.

source: {
  type: 'node',
  snippet: `<meta name="robots" content="${artifacts.MetaRobots}" />`,
 //selector: ??
},

This causes resulting table item title to be set to 'undefined':

undefined-title

We should show element selector instead, just like axe-core audits do:

axe-title

However, to build a full selector we'd need class+id+nodeName for given node and all its ancestors which would require more work from the gatherers.

font-size audit is in a bit better situation because we do have all the data needed from the gatherer, however, we still can't reuse getSelector from axe-core since we don't have real DOM nodes, but rather devtools protocol nodes.
I've put together a simpler alternative that would work here, but it doesn't guarantee selectors to be pretty or unique. For now we decided to show only id, class or node name of the parent element.

@patrickhulce
Copy link
Collaborator

patrickhulce commented Jan 17, 2018

Decided to do something simple here just using the class, id, and name/type attributes of the current node and not worry about parents

Function to make the nodes clickable in devtools

function getNodePath(node) {
function getNodeIndex(node) {
let index = 0;
while (node = node.previousSibling) {
// skip empty text nodes
if (node.nodeType === Node.TEXT_NODE &&
node.textContent.trim().length === 0) continue;
index++;
}
return index;
}
const path = [];
while (node && node.parentNode) {
const index = getNodeIndex(node);
path.push([index, node.nodeName]);
node = node.parentNode;
}
path.reverse();
return path.join(',');
}

@brendankenny
Copy link
Member

we fixed the undefined hover when we first added types to details-renderer in #5195, and #6683 and #8961 are taking up the mantle here, so I'm going to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants