fix(diffs): tighten rendering quality

This commit is contained in:
Gustavo Madeira Santana
2026-02-28 23:03:28 -05:00
parent 0f72000c96
commit 9257dfb5c0
4 changed files with 79 additions and 28 deletions

View File

@@ -122,15 +122,29 @@ export class PlaywrightDiffScreenshotter implements DiffScreenshotter {
throw new Error("Diff frame was lost after resizing.");
}
const dpr = await page.evaluate(() => window.devicePixelRatio || 1);
// Raw clip in CSS px
const rawX = Math.max(box.x - padding, 0);
const rawY = Math.max(box.y - padding, 0);
const rawRight = rawX + clipWidth;
const rawBottom = rawY + clipHeight;
// Snap to device-pixel grid to avoid soft text from sub-pixel crop
const x = Math.floor(rawX * dpr) / dpr;
const y = Math.floor(rawY * dpr) / dpr;
const right = Math.ceil(rawRight * dpr) / dpr;
const bottom = Math.ceil(rawBottom * dpr) / dpr;
await page.screenshot({
path: params.outputPath,
type: "png",
scale: "device",
clip: {
x: Math.max(box.x - padding, 0),
y: Math.max(box.y - padding, 0),
width: clipWidth,
height: clipHeight,
x,
y,
width: right - x,
height: bottom - y,
},
});
return params.outputPath;
@@ -233,7 +247,7 @@ async function acquireSharedBrowser(params: {
.launch({
headless: true,
...(executablePath ? { executablePath } : {}),
args: ["--disable-dev-shm-usage", "--disable-gpu"],
args: ["--disable-dev-shm-usage"],
})
.then((browser) => {
if (sharedBrowserState?.browserPromise === browserPromise) {