Skip to content

Commit 76e1606

Browse files
author
Logan Graham
committed
add scroll offests to clip and ignore region dynamic calculation
1 parent e75b5c7 commit 76e1606

File tree

1 file changed

+8
-2
lines changed
  • visual-js/visual-playwright/src

1 file changed

+8
-2
lines changed

visual-js/visual-playwright/src/api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ ${e instanceof Error ? e.message : JSON.stringify(e)}
193193
const clientDims = clipElement.getBoundingClientRect();
194194
let { x, y, height, width } = clientDims;
195195

196+
// Add scroll offset to coordinates in case page is scrolled prior to capture
197+
({ x, y } = {
198+
x: x + window.scrollX,
199+
y: y + window.scrollY,
200+
});
201+
196202
// corrected coordinates
197203
const cX = x < 0 ? Math.abs(x) : 0;
198204
const cY = y < 0 ? Math.abs(y) : 0;
@@ -243,8 +249,8 @@ ${e instanceof Error ? e.message : JSON.stringify(e)}
243249

244250
selectorRegions.push({
245251
name: selector,
246-
x: Math.round(rect.x),
247-
y: Math.round(rect.y),
252+
x: Math.round(rect.x + window.scrollX),
253+
y: Math.round(rect.y + window.scrollY),
248254
height: Math.round(rect.height),
249255
width: Math.round(rect.width),
250256
});

0 commit comments

Comments
 (0)