Skip to content

Commit dc302a8

Browse files
committed
fix: add edge cases
1 parent 44e0ddb commit dc302a8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/image-comparison-core/src/methods/screenshots.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ export async function getDesktopFullPageScreenshotsData(browserInstance:Webdrive
401401
imageYPosition = remainingContent >= actualInnerHeight
402402
? safariTopDropShadowCssPixels
403403
: actualInnerHeight - remainingContent - safariBottomCropOffsetCssPixels
404+
405+
// If remainingContent is too small, we might get negative imageYPosition or invalid dimensions
406+
if (imageYPosition < 0) {
407+
imageYPosition = actualInnerHeight - remainingContent
408+
imageHeight = remainingContent
409+
} else if (imageYPosition + imageHeight > screenshotSize.height) {
410+
imageHeight = screenshotSize.height - imageYPosition
411+
}
404412
} else if (!isFirstImage) {
405413
// Non-last, non-first images: crop 1px from top
406414
imageYPosition = safariTopDropShadowCssPixels
@@ -414,6 +422,15 @@ export async function getDesktopFullPageScreenshotsData(browserInstance:Webdrive
414422
: 0
415423
}
416424

425+
// Ensure imageYPosition and imageHeight are valid for all cases
426+
if (imageYPosition < 0) {
427+
imageHeight += imageYPosition
428+
imageYPosition = 0
429+
}
430+
if (imageYPosition + imageHeight > screenshotSize.height) {
431+
imageHeight = screenshotSize.height - imageYPosition
432+
}
433+
417434
// Calculate based on where the previous image ends
418435
// Previous image's canvasYPosition + previous image's height
419436
let canvasYPosition: number

0 commit comments

Comments
 (0)