From ea4116e64546dca6b41160c50a42c69e86cc3fcd Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 18 Oct 2024 13:51:04 +0200 Subject: [PATCH] don't draw checkerboard when canvas is uncaptured --- packages/trace-viewer/src/sw/snapshotRenderer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/trace-viewer/src/sw/snapshotRenderer.ts b/packages/trace-viewer/src/sw/snapshotRenderer.ts index ff168c8dab..6fa91d472b 100644 --- a/packages/trace-viewer/src/sw/snapshotRenderer.ts +++ b/packages/trace-viewer/src/sw/snapshotRenderer.ts @@ -459,20 +459,20 @@ function snapshotScript(...targetIds: (string | undefined)[]) { const xEnd = boundingRect.right / window.innerWidth; const yEnd = boundingRect.bottom / window.innerHeight; - drawCheckerboard(context, canvas); - + const partiallyUncaptured = xEnd > 1 || yEnd > 1; const fullyUncaptured = xStart > 1 || yStart > 1; if (fullyUncaptured) { canvas.title = `Playwright couldn't capture canvas contents because it's located outside the viewport.`; continue; } + drawCheckerboard(context, canvas); + context.drawImage(img, xStart * img.width, yStart * img.height, (xEnd - xStart) * img.width, (yEnd - yStart) * img.height, 0, 0, canvas.width, canvas.height); if (isUnderTest) // eslint-disable-next-line no-console console.log(`canvas drawn:`, JSON.stringify([xStart, yStart, xEnd, yEnd].map(v => Math.floor(v * 100)))); - const partiallyUncaptured = xEnd > 1 || yEnd > 1; if (partiallyUncaptured) canvas.title = `Playwright couldn't capture full canvas contents because it's located partially outside the viewport.`; else