The button overlaps on your phone, but your coding agent keeps changing the wrong CSS. Every guessed fix costs review time and can break a layout that was working. Screenshots at consistent viewport sizes give you and the agent something concrete to compare.
Run the page locally, capture a before image at phone, tablet, and desktop sizes, and ask the agent to describe the problem before changing code. After the fix, capture the same views again and inspect both sets. Keep the images with the handoff so “done” comes with evidence.
Make the bug visible before changing code
A text report such as “the button overlaps on mobile” leaves questions open. Which button? Does it cover text, leave the screen, or overlap another control? Does it happen on initial load or only after opening a menu?
Add the page URL, the action needed to reach the broken state, and what you expected to see. If the problem depends on a long title, an empty list, or a signed-in account, include a safe way to reproduce that state too.
The screenshot loop below captures the initial page state. It’s a starting point, not a complete test of every interaction. If the bug appears after a click, ask the agent to add that action to the script before taking the image. Use test data rather than customer information, and check screenshots for private content before sharing them.
If you want a harness to try this in, you can try the zcode agent harness free (our invite link). Whatever you use, confirm that your agent can actually open image files; a list of filenames alone doesn’t let it inspect the layout.
Capture the same page at three sizes
In a Node project, install the Playwright library and its Chromium browser using the commands in the Playwright library guide:
npm i -D playwright
npx playwright install chromium
Save the script below as screenshots.cjs in your project. The dimensions are examples you can change to match the brief. Playwright documents setting a viewport and saving a full-page screenshot.
const { chromium } = require('playwright');
const fs = require('node:fs/promises');
(async () => {
const [stage, url] = process.argv.slice(2);
if (!['before', 'after'].includes(stage) || !url) {
throw new Error('Usage: node screenshots.cjs before|after URL');
}
const sizes = [
['phone', 390, 844],
['tablet', 768, 1024],
['desktop', 1440, 900],
];
const dir = `screenshots/${stage}`;
await fs.mkdir(dir, { recursive: true });
const browser = await chromium.launch();
try {
for (const [name, width, height] of sizes) {
const context = await browser.newContext({
viewport: { width, height },
});
const page = await context.newPage();
const response = await page.goto(url);
if (!response || !response.ok()) {
throw new Error(`Page failed to load: ${url}`);
}
await page.evaluate(() => document.fonts.ready);
await page.screenshot({ path: `${dir}/${name}.png`, fullPage: true });
await context.close();
}
} finally {
await browser.close();
}
})().catch(error => {
console.error(error);
process.exitCode = 1;
});
Start your app using its usual development command. Then replace the example address below with the actual page URL:
node screenshots.cjs before http://localhost:3000/
The images go into screenshots/before. The script waits for fonts and checks the page response, but you may also need to wait for app-specific content or reproduce an interaction before capture. Open the images and confirm they show the intended page and state, not a loading screen or sign-in page.
Ask for a fix with before-and-after evidence
Once the before images show the bug, give the agent a bounded brief. Replace the placeholders and keep the instruction to inspect the images before editing:
Page: [local URL]
Bug: [what overlaps, where, and after which action]
Expected: [what should appear instead]
Run screenshots.cjs with the "before" stage.
Open and inspect each image. Describe the visible problem
and name the file and viewport where you see it.
Make the smallest relevant fix. Then run the script with
the "after" stage at the same URL and viewports.
Open the new images and compare them with the originals.
Report the changed files, the commands and checks run,
and the before/after image paths. Call out anything you
could not inspect or verify. Do not claim success without
the images.
After the code changes, the corresponding command is:
node screenshots.cjs after http://localhost:3000/
The before and after folders stay separate. Running the same stage again replaces that stage’s images, so copy out anything you need to preserve first.
Compare each pair at the same width. Check the reported overlap, then look around it: a button moved into place may have pushed another control off-screen. If the agent can’t see images in its environment, open them yourself and give it specific observations rather than treating its guess as a visual review.
If you run this loop often and want a coding plan for it, here's our coupon for 10% off GLM coding plans.
Add a visual guard where it earns its keep
For a layout you expect to remain stable, consider a visual comparison after you’ve reviewed the corrected image. Playwright’s visual comparison guide explains how toHaveScreenshot() creates a reference image and compares later runs against it.
This uses Playwright Test, which is separate from the library script above. Create a test for the relevant page and state, generate the reference, and inspect it before treating it as the expected result. A reference captured while the bug is still present can preserve the wrong appearance.
Keep the test environment consistent with the baseline. Playwright notes that rendering can differ with the operating system, browser settings, fonts, and other conditions. Changing content can also create distracting differences, so use stable test data where possible.
When a comparison fails, inspect the images and the diff before updating the reference. An intentional design change may need a new baseline; an unexplained overlap needs a fix. A passing comparison helps catch visual changes in the tested state, but it doesn’t prove the page works everywhere.
Check what screenshots can’t settle
A viewport-sized screenshot is useful evidence, but it isn’t a substitute for trying the page on a real device. Check the affected flow on a phone or tablet when the job requires it, including scrolling and tapping the control.
Look at fonts after they load: a fallback font can change wrapping and make the before-and-after comparison misleading. Check dark mode if the page supports it, and inspect any menu, modal, or error state involved in the bug. A full-page image can show the layout while still missing a problem that appears only during interaction.
Before accepting the fix, review the code as well as the pictures. Use Review an AI-written diff in 10 minutes: a checklist for a focused pass. There's more on our blog too.
The checklist
Save this for the next handoff:
[ ] Page URL and broken state are clear
[ ] Before images show the actual bug
[ ] Phone, tablet, and desktop views were captured
[ ] Agent described the images before editing
[ ] After images use the same page and viewports
[ ] Each before/after pair was inspected
[ ] Changed files and test results were reviewed
[ ] Real-device, font, and dark-mode gaps are noted
[ ] Images are safe to share and included in the handoff
If this helped you catch a layout bug, a small tip on WURK is a nice way to say so.






Latest comments
0