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: normalize creation of NodeValue #11877

Merged
merged 53 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
90018b2
core(driver): create page code using structured interface
connorjclark May 20, 2020
f7e38f5
rename type
connorjclark May 20, 2020
78f386a
pr feedback
connorjclark May 20, 2020
32856e7
no strings
connorjclark May 20, 2020
e2dd63d
test
connorjclark May 20, 2020
f38bf41
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced
connorjclark Jun 4, 2020
ce9839b
test
connorjclark Jun 4, 2020
4c903de
restrucutre
connorjclark Jun 5, 2020
0413a4a
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced
connorjclark Jun 12, 2020
d4bd2bf
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced
connorjclark Jun 17, 2020
02dc215
remove obj
connorjclark Jun 17, 2020
ce2827a
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced
connorjclark Jul 15, 2020
c81a636
update master
connorjclark Nov 5, 2020
70d8210
rm dead code
connorjclark Nov 5, 2020
df5e8dd
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced
connorjclark Nov 10, 2020
4e59476
adam feedback
connorjclark Nov 10, 2020
147b98c
fix tests
connorjclark Nov 10, 2020
a4051a1
fix mangle issues
connorjclark Nov 10, 2020
9eea206
wip
connorjclark Nov 10, 2020
d79b23f
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced-2
connorjclark Dec 2, 2020
b8c76ed
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced-2
connorjclark Dec 2, 2020
2088109
fix
connorjclark Dec 2, 2020
7b01e8c
wip
connorjclark Dec 2, 2020
4cc1eea
fix
connorjclark Dec 2, 2020
aae0a9f
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced-2
connorjclark Dec 2, 2020
77af88d
fix tests
connorjclark Dec 3, 2020
d35fd5e
fix
connorjclark Dec 3, 2020
eb897cf
tmp
connorjclark Dec 21, 2020
9c10cda
Merge remote-tracking branch 'origin/master' into driver-eval-enhanced-2
connorjclark Dec 21, 2020
d643baf
update
connorjclark Dec 21, 2020
9638b90
master
connorjclark Dec 21, 2020
c526772
fixtest
connorjclark Dec 21, 2020
b893bb1
fix
connorjclark Dec 22, 2020
606db62
oops
connorjclark Dec 22, 2020
8c98d05
pr
connorjclark Dec 22, 2020
ed13e97
Merge branch 'driver-eval-enhanced-2' into node-details-yay
connorjclark Dec 22, 2020
3195324
update
connorjclark Dec 22, 2020
af84552
Merge remote-tracking branch 'origin/master' into node-details-yay
connorjclark Dec 22, 2020
f799583
update
connorjclark Dec 22, 2020
f2b649b
Merge remote-tracking branch 'origin/master' into node-details-yay
connorjclark Dec 22, 2020
d850391
more
connorjclark Dec 22, 2020
7b7aeb3
deps
connorjclark Dec 23, 2020
2e37d0b
Merge remote-tracking branch 'origin/master' into node-details-yay
connorjclark Dec 23, 2020
685d356
fix tests
connorjclark Dec 23, 2020
a04e261
test
connorjclark Dec 23, 2020
098411b
rename
connorjclark Dec 23, 2020
cc8cdb3
no meta els
connorjclark Dec 23, 2020
f763a1f
tweak
connorjclark Dec 23, 2020
25210c5
revert
connorjclark Dec 23, 2020
ba30ab5
update
connorjclark Jan 11, 2021
0679ff5
Apply suggestions from code review
connorjclark Jan 11, 2021
68ee66f
kiss
connorjclark Jan 11, 2021
d7c562c
Merge branch 'node-details-yay' of github.com:GoogleChrome/lighthouse…
connorjclark Jan 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lighthouse-core/audits/accessibility/axe-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,8 @@ class AxeAudit extends Audit {
if (rule && rule.nodes) {
items = rule.nodes.map(axeNode => ({
node: {
type: /** @type {'node'} */ ('node'),
lhId: axeNode.node.lhId,
selector: axeNode.node.selector,
path: axeNode.node.devtoolsNodePath,
snippet: axeNode.node.snippet,
boundingRect: axeNode.node.boundingRect,
...Audit.makeNodeValue(axeNode.node),
explanation: axeNode.failureSummary,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why do we add explanation here?

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like this gets included in the report 🤔 . Is it supposed to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only purpose I can see is in the smoke tests.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we add explanation here?

#5402

nodeLabel: axeNode.node.nodeLabel,
},
}));
}
Expand Down
14 changes: 14 additions & 0 deletions lighthouse-core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ class Audit {
};
}

/**
* @param {LH.Artifacts.NodeDetails} node
* @return {LH.Audit.Details.NodeValue}
*/
static makeNodeValue(node) {
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
const {devtoolsNodePath, ...rest} = node;

return {
type: 'node',
...rest,
path: devtoolsNodePath,
};
}

/**
* @param {number|null} score
* @param {LH.Audit.ScoreDisplayMode} scoreDisplayMode
Expand Down
6 changes: 1 addition & 5 deletions lighthouse-core/audits/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,7 @@ class AutocompleteAudit extends Audit {
continue;
}
failingFormsData.push({
node: {
type: /** @type {'node'} */ ('node'),
snippet: input.node.snippet,
nodeLabel: input.node.nodeLabel,
},
node: Audit.makeNodeValue(input.node),
suggestion: suggestion,
current: input.autocomplete.attribute,
});
Expand Down
16 changes: 2 additions & 14 deletions lighthouse-core/audits/dobetterweb/dom-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,12 @@ class DOMSize extends Audit {
value: stats.totalBodyElements,
},
{
node: {
type: /** @type {'node'} */ ('node'),
path: stats.depth.devtoolsNodePath,
snippet: stats.depth.snippet,
selector: stats.depth.selector,
nodeLabel: stats.depth.nodeLabel,
},
node: Audit.makeNodeValue(stats.depth),
statistic: str_(UIStrings.statisticDOMDepth),
value: stats.depth.max,
},
{
node: {
type: /** @type {'node'} */ ('node'),
path: stats.width.devtoolsNodePath,
snippet: stats.width.snippet,
selector: stats.width.selector,
nodeLabel: stats.width.nodeLabel,
},
node: Audit.makeNodeValue(stats.width),
statistic: str_(UIStrings.statisticDOMWidth),
value: stats.width.max,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,7 @@ class ExternalAnchorsUseRelNoopenerAudit extends Audit {
})
.map(anchor => {
return {
node: {
type: /** @type {'node'} */ ('node'),
path: anchor.node.devtoolsNodePath || '',
selector: anchor.node.selector || '',
nodeLabel: anchor.node.nodeLabel || '',
snippet: anchor.node.snippet || '',
},
node: Audit.makeNodeValue(anchor.node),
href: anchor.href || 'Unknown',
target: anchor.target || '',
rel: anchor.rel || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ class PasswordInputsCanBePastedIntoAudit extends Audit {

/** @type {LH.Audit.Details.Table['items']} */
const items = [];

passwordInputsWithPreventedPaste.forEach(input => {
items.push({
node: {
type: /** @type {'node'} */ ('node'),
snippet: input.node.snippet,
path: input.node.devtoolsNodePath,
},
node: Audit.makeNodeValue(input.node),
});
});

Expand Down
10 changes: 1 addition & 9 deletions lighthouse-core/audits/largest-contentful-paint-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ class LargestContentfulPaintElement extends Audit {
const lcpElementDetails = [];
if (lcpElement) {
lcpElementDetails.push({
node: {
type: /** @type {'node'} */ ('node'),
lhId: lcpElement.node.lhId,
path: lcpElement.node.devtoolsNodePath,
selector: lcpElement.node.selector,
nodeLabel: lcpElement.node.nodeLabel,
snippet: lcpElement.node.snippet,
boundingRect: lcpElement.node.boundingRect,
},
node: Audit.makeNodeValue(lcpElement.node),
});
}

Expand Down
10 changes: 1 addition & 9 deletions lighthouse-core/audits/layout-shift-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,7 @@ class LayoutShiftElements extends Audit {

const clsElementData = clsElements.map(element => {
return {
node: {
type: /** @type {'node'} */ ('node'),
lhId: element.node.lhId,
path: element.node.devtoolsNodePath,
selector: element.node.selector,
nodeLabel: element.node.nodeLabel,
snippet: element.node.snippet,
boundingRect: element.node.boundingRect,
},
node: Audit.makeNodeValue(element.node),
score: element.score,
};
});
Expand Down
12 changes: 2 additions & 10 deletions lighthouse-core/audits/non-composited-animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,11 @@ class NonCompositedAnimations extends Audit {
};
}

/** @type LH.Audit.Details.TableItem[] */
/** @type {LH.Audit.Details.TableItem[]} */
adamraine marked this conversation as resolved.
Show resolved Hide resolved
const results = [];
let shouldAddAnimationNameColumn = false;
artifacts.TraceElements.forEach(element => {
if (element.traceEventType !== 'animation') return;
/** @type LH.Audit.Details.NodeValue */
const node = {
type: 'node',
path: element.node.devtoolsNodePath,
selector: element.node.selector,
nodeLabel: element.node.nodeLabel,
snippet: element.node.snippet,
};

const animations = element.animations || [];
const animationReasons = new Map();
Expand Down Expand Up @@ -171,7 +163,7 @@ class NonCompositedAnimations extends Audit {
}

results.push({
node,
node: Audit.makeNodeValue(element.node),
subItems: {
type: 'subitems',
items: allFailureReasons,
Expand Down
8 changes: 1 addition & 7 deletions lighthouse-core/audits/seo/crawlable-anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ class CrawlableAnchors extends Audit {
/** @type {LH.Audit.Details.Table['items']} */
const itemsToDisplay = failingAnchors.map(anchor => {
return {
node: {
type: 'node',
path: anchor.node.devtoolsNodePath || '',
selector: anchor.node.selector || '',
nodeLabel: anchor.node.nodeLabel || '',
snippet: anchor.node.snippet || '',
},
node: Audit.makeNodeValue(anchor.node),
};
});

Expand Down
18 changes: 11 additions & 7 deletions lighthouse-core/audits/seo/hreflang.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ class Hreflang extends Audit {
}

if (link.source === 'head') {
source = {
type: 'node',
snippet: `<link rel="alternate" hreflang="${link.hreflang}" href="${link.hrefRaw}" />`,
path: link.node !== null ? link.node.devtoolsNodePath : '',
selector: link.node !== null ? link.node.selector : '',
nodeLabel: link.node !== null ? link.node.nodeLabel : '',
};
if (link.node) {
source = {
...Audit.makeNodeValue(link.node),
snippet: `<link rel="alternate" hreflang="${link.hreflang}" href="${link.hrefRaw}" />`,
};
} else {
source = {
type: 'node',
snippet: `<link rel="alternate" hreflang="${link.hreflang}" href="${link.hrefRaw}" />`,
};
}
} else if (link.source === 'headers') {
source = `Link: <${link.hrefRaw}>; rel="alternate"; hreflang="${link.hreflang}"`;
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/seo/is-crawlable.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class IsCrawlable extends Audit {
if (isBlocking) {
blockingDirectives.push({
source: {
type: /** @type {'node'} */ ('node'),
...Audit.makeNodeValue(metaRobots.node),
snippet: `<meta name="robots" content="${metaRobotsContent}" />`,
},
});
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/seo/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Plugins extends Audit {

return {
source: {
type: /** @type {'node'} */ ('node'),
...Audit.makeNodeValue(plugin.node),
snippet: `<${tagName}${attributes}>${params}</${tagName}>`,
Copy link
Member

Choose a reason for hiding this comment

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

this ends up rendering completely differently in the report (it was basically just <span class="lh-node"><div class="lh-node__snippet">${snippet}</div></span> before). Does it work well for this audit (with these sometimes very long snippets)? Should it use the default NodeDetails snippet instead of its custom one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sometimes very long snippets

examples?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should it use the default NodeDetails snippet instead of its custom one?

Maybe, if we wanted to we could parameterize getNodeDetails/Snippet to accept a list of attribute names (give it SOURCE_PARAMS).

Copy link
Member

Choose a reason for hiding this comment

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

Does it work well for this audit (with these sometimes very long snippets)?

examples?

unlike the getNodeDetails().snippet, the plugin attributes and params aren't ever truncated in number or string length, so it could be as long as the original page wanted

Should it use the default NodeDetails snippet instead of its custom one?

Maybe, if we wanted to we could parameterize getNodeDetails/Snippet to accept a list of attribute names (give it SOURCE_PARAMS).

yeah, though I guess do we care about the <param> elements or are the element attributes (plus all the other node details stuff) sufficient to identify it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ehhh let's just use the default snippet so we can keep this simple. it'll be more identifiable now with the devtools node path and everything else, and truncation will prevent the worse cases.

},
};
Expand Down
7 changes: 1 addition & 6 deletions lighthouse-core/audits/seo/tap-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,8 @@ function targetToTableNode(target) {
const boundingRect = getBoundingRect(target.clientRects);

return {
type: 'node',
lhId: target.node.lhId,
snippet: target.node.snippet,
path: target.node.devtoolsNodePath,
selector: target.node.selector,
...Audit.makeNodeValue(target.node),
boundingRect,
Copy link
Member

Choose a reason for hiding this comment

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

Which boundingRect should be used here? Using the boundingRect of all clientRects goes back to the first commit of #10716, but getNodeDetails also didn't exist back then, so that might have just been the most convenient way to do it at the time. Should it be the just node.boundingRect? When can the two differ? getBoundingClientRect should normally contain all child rects, but does it ever differ (transforms or something?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll followup with this in a different PR.

nodeLabel: target.node.nodeLabel,
};
}

Expand Down
9 changes: 2 additions & 7 deletions lighthouse-core/audits/unsized-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,10 @@ class UnsizedImages extends Audit {

if (isFixedImage || UnsizedImages.isSizedImage(image)) continue;
const url = URL.elideDataURI(image.src);

unsizedImages.push({
url,
node: {
type: /** @type {'node'} */ ('node'),
path: image.node.devtoolsNodePath,
selector: image.node.selector,
nodeLabel: image.node.nodeLabel,
snippet: image.node.snippet,
},
node: Audit.makeNodeValue(image.node),
});
}

Expand Down
18 changes: 14 additions & 4 deletions lighthouse-core/gather/gatherers/meta-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
const Gatherer = require('./gatherer.js');
const pageFunctions = require('../../lib/page-functions.js');

/* globals getElementsInDocument */
/* globals getElementsInDocument getNodeDetails */

/* istanbul ignore next */
function collectMetaElements() {
// @ts-expect-error - getElementsInDocument put into scope via stringification
const metas = /** @type {HTMLMetaElement[]} */ (getElementsInDocument('head meta'));
const functions = /** @type {typeof pageFunctions} */({
// @ts-expect-error - getElementsInDocument put into scope via stringification
getElementsInDocument,
// @ts-expect-error - getNodeDetails put into scope via stringification
getNodeDetails,
});

const metas = /** @type {HTMLMetaElement[]} */ (functions.getElementsInDocument('head meta'));
return metas.map(meta => {
/** @param {string} name */
const getAttribute = name => {
Expand All @@ -27,6 +33,7 @@ function collectMetaElements() {
property: getAttribute('property'),
httpEquiv: meta.httpEquiv ? meta.httpEquiv.toLowerCase() : undefined,
charset: getAttribute('charset'),
node: functions.getNodeDetails(meta),
};
});
}
Expand All @@ -44,7 +51,10 @@ class MetaElements extends Gatherer {
return driver.evaluate(collectMetaElements, {
args: [],
useIsolation: true,
deps: [pageFunctions.getElementsInDocument],
deps: [
pageFunctions.getElementsInDocument,
pageFunctions.getNodeDetailsString,
],
});
}
}
Expand Down
22 changes: 17 additions & 5 deletions lighthouse-core/gather/gatherers/seo/embedded-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
*/
'use strict';

/* globals getElementsInDocument */
/* globals getElementsInDocument getNodeDetails */

const Gatherer = require('../gatherer.js');
const pageFunctions = require('../../../lib/page-functions.js');

/**
* @return {LH.Artifacts.EmbeddedContentInfo[]}
*/
function getEmbeddedContent() {
const functions = /** @type {typeof pageFunctions} */({
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
// @ts-expect-error - getElementsInDocument put into scope via stringification
getElementsInDocument,
// @ts-expect-error - getNodeDetails put into scope via stringification
getNodeDetails,
});

const selector = 'object, embed, applet';
/** @type {HTMLElement[]} */
// @ts-expect-error - getElementsInDocument put into scope via stringification
const elements = getElementsInDocument(selector);
const elements = functions.getElementsInDocument(selector);
return elements
.map(node => ({
tagName: node.tagName,
Expand All @@ -28,6 +36,7 @@ function getEmbeddedContent() {
name: el.getAttribute('name') || '',
value: el.getAttribute('value') || '',
})),
node: functions.getNodeDetails(node),
}));
}

Expand All @@ -39,7 +48,10 @@ class EmbeddedContent extends Gatherer {
afterPass(passContext) {
return passContext.driver.evaluate(getEmbeddedContent, {
args: [],
deps: [pageFunctions.getElementsInDocument],
deps: [
pageFunctions.getElementsInDocument,
pageFunctions.getNodeDetailsString,
],
});
}
}
Expand Down
Loading