Skip to content

Commit 2e3cd5c

Browse files
authoredDec 17, 2020
core(full-page-screenshot): handle ShadowRoots (#11852)
1 parent 966a206 commit 2e3cd5c

File tree

4 files changed

+692
-22
lines changed

4 files changed

+692
-22
lines changed
 

‎lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-expectations.js

+24
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,30 @@ const expectations = [
429429
}],
430430
},
431431
},
432+
'full-page-screenshot': {
433+
score: null,
434+
details: {
435+
type: 'full-page-screenshot',
436+
screenshot: {
437+
width: 360,
438+
// Allow for differences in platforms.
439+
height: '3755±5',
440+
data: /^data:image\/jpeg;.{500,}/,
441+
},
442+
nodes: {
443+
'page-0-IMG': {
444+
// Test that these are numbers and in the ballpark.
445+
top: '650±50',
446+
bottom: '650±50',
447+
left: '10±10',
448+
right: '120±20',
449+
width: '120±20',
450+
height: '20±20',
451+
},
452+
// And then many more nodes.
453+
},
454+
},
455+
},
432456
},
433457
},
434458
},

‎lighthouse-core/lib/page-functions.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -467,26 +467,27 @@ function getNodeDetailsImpl(element) {
467467
window.__lighthouseNodesDontTouchOrAllVarianceGoesAway = new Map();
468468
}
469469

470+
const htmlElement = element instanceof ShadowRoot ? element.host : element;
471+
470472
// Create an id that will be unique across all execution contexts.
471473
// The id could be any arbitrary string, the exact value is not important.
472474
// For example, tagName is added only because it might be useful for debugging.
473475
// But execution id and map size are added to ensure uniqueness.
474476
// We also dedupe this id so that details collected for an element within the same
475477
// pass and execution context will share the same id. Not technically important, but
476478
// cuts down on some duplication.
477-
let lhId = window.__lighthouseNodesDontTouchOrAllVarianceGoesAway.get(element);
479+
let lhId = window.__lighthouseNodesDontTouchOrAllVarianceGoesAway.get(htmlElement);
478480
if (!lhId) {
479481
lhId = [
480482
window.__lighthouseExecutionContextId !== undefined ?
481483
window.__lighthouseExecutionContextId :
482484
'page',
483485
window.__lighthouseNodesDontTouchOrAllVarianceGoesAway.size,
484-
element.tagName,
486+
htmlElement.tagName,
485487
].join('-');
486-
window.__lighthouseNodesDontTouchOrAllVarianceGoesAway.set(element, lhId);
488+
window.__lighthouseNodesDontTouchOrAllVarianceGoesAway.set(htmlElement, lhId);
487489
}
488490

489-
const htmlElement = element instanceof ShadowRoot ? element.host : element;
490491
const details = {
491492
lhId,
492493
devtoolsNodePath: getNodePath(element),

‎lighthouse-core/test/results/artifacts/artifacts.json

+332-9
Large diffs are not rendered by default.

‎lighthouse-core/test/results/sample_v2.json

+331-9
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.