Skip to content

Commit dd40267

Browse files
committed
Merge remote-tracking branch 'origin/master' into mocha-core
2 parents 1c5bbb9 + 6e262f2 commit dd40267

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@
147147

148148
// Ensure long-task collection still works when performance.now is redefined
149149
window.performance.now = 'right now';
150+
151+
// Ensure bounding rectangles still work when getBoundingClientRect is overriden.
152+
window.HTMLElement.prototype.getBoundingClientRect = function() {
153+
return {top: '', left: ''};
154+
};
150155
</script>
151156

152157
<div>

lighthouse-core/gather/driver/execution-context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class ExecutionContext {
215215
window.__nativePerformance = window.performance;
216216
window.__nativeFetch = window.fetch;
217217
window.__ElementMatches = window.Element.prototype.matches;
218+
window.__HTMLElementBoundingClientRect = window.HTMLElement.prototype.getBoundingClientRect;
218219
// Ensure the native `performance.now` is not overwritable.
219220
const performance = window.performance;
220221
const performanceNow = window.performance.now;

lighthouse-core/gather/gatherers/iframe-elements.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ const pageFunctions = require('../../lib/page-functions.js');
1717
*/
1818
/* c8 ignore start */
1919
function collectIFrameElements() {
20+
const realBoundingClientRect = window.__HTMLElementBoundingClientRect ||
21+
window.HTMLElement.prototype.getBoundingClientRect;
22+
2023
// @ts-expect-error - put into scope via stringification
2124
const iFrameElements = getElementsInDocument('iframe'); // eslint-disable-line no-undef
2225
return iFrameElements.map(/** @param {HTMLIFrameElement} node */ (node) => {
23-
const clientRect = node.getBoundingClientRect();
26+
const clientRect = realBoundingClientRect.call(node);
2427
const {top, bottom, left, right, width, height} = clientRect;
2528
return {
2629
id: node.id,

lighthouse-core/lib/page-functions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,10 @@ function getNodeLabel(element) {
434434
* @return {LH.Artifacts.Rect}
435435
*/
436436
function getBoundingClientRect(element) {
437+
const realBoundingClientRect = window.__HTMLElementBoundingClientRect ||
438+
window.HTMLElement.prototype.getBoundingClientRect;
437439
// The protocol does not serialize getters, so extract the values explicitly.
438-
const rect = element.getBoundingClientRect();
440+
const rect = realBoundingClientRect.call(element);
439441
return {
440442
top: Math.round(rect.top),
441443
bottom: Math.round(rect.bottom),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ describe('Page Functions', () => {
2121
global.Node = Node;
2222
global.HTMLElement = HTMLElement;
2323
global.document = document;
24-
global.window = {};
24+
global.window = {
25+
HTMLElement, // for getBoundingClientRect fallback.
26+
};
2527
});
2628

2729
afterAll(() => {

types/externs.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare global {
2323
__nativeFetch: typeof fetch,
2424
__nativeURL: typeof URL;
2525
__ElementMatches: Element['matches'];
26+
__HTMLElementBoundingClientRect: HTMLElement['getBoundingClientRect'];
2627

2728
/** Used for monitoring long tasks in the test page. */
2829
____lastLongTask?: number;

0 commit comments

Comments
 (0)