Screenshot Pages
Capture screenshots of pages affected by current changes using agent-browser.
Context
Current branch:
code
`! git branch --show-current`
Changed files:
code
`! git diff --name-only main...HEAD`
Steps
- •
Check prerequisites:
- •Verify
agent-browseris available:which agent-browser - •If not installed, tell the user to install it:
npm install -g @anthropic-ai/agent-browser - •Ensure
.screenshots/directory exists:mkdir -p .screenshots
- •Verify
- •
Parse arguments:
- •If URL paths provided (e.g.,
/pricing /features) → screenshot those pages - •If
--compareflag → do before/after comparison (see step 5) - •If no args → infer affected pages from the git diff. Look at changed files in
app/pages/to determine routes. If changes are only in components/blocks, ask the user which pages to screenshot.
- •If URL paths provided (e.g.,
- •
Start dev server in background:
bashpnpm dev & DEV_PID=$!
Wait for
http://localhost:3000to respond:bashfor i in {1..30}; do curl -s -o /dev/null http://localhost:3000 && break || sleep 2; done - •
Capture screenshots for each page path:
bash# Desktop (1440x900) agent-browser open "http://localhost:3000<path>" agent-browser wait --load networkidle agent-browser set viewport 1440 900 agent-browser screenshot ".screenshots/<name>-desktop.png" --full # Mobile (390x844) agent-browser set viewport 390 844 agent-browser screenshot ".screenshots/<name>-mobile.png" --full
- •For the homepage
/, usehomeas the name - •For other paths like
/pricing, use the last segment as the name (e.g.,pricing)
- •For the homepage
- •
Before/after mode (when
--compareis passed):- •First, stash current changes:
git stash - •Restart dev server, wait for it
- •Screenshot each page with
-before-desktop.png/-before-mobile.pngsuffixes - •Restore changes:
git stash pop - •Restart dev server, wait for it
- •Screenshot each page with
-after-desktop.png/-after-mobile.pngsuffixes
- •First, stash current changes:
- •
Kill dev server:
bashkill $DEV_PID
- •
Output results as a markdown table.
Output Format
For standard mode:
markdown
## Screenshots | Page | Desktop | Mobile | |------|---------|--------| | /pricing |  |  |
For compare mode:
markdown
## Screenshots (Before / After) ### /pricing | Viewport | Before | After | |----------|--------|-------| | Desktop |  |  | | Mobile |  |  |
Important
- •Always kill the dev server when done, even if something fails
- •Screenshots go in
.screenshots/at the repo root (already gitignored) - •If
agent-browsercommands fail, suggest the user check that the browser agent is running