pr-screenshot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePR Screenshot Skill
PR截图Skill
Add before/after comparison screenshots to a pull request using browser automation and GitHub CDN. This captures the UI on the base branch (before) and the PR branch (after), then presents them in a side-by-side comparison table.
通过浏览器自动化和GitHub CDN为拉取请求(PR)添加前后对比截图。该技能会在基础分支(变更前)和PR分支(变更后)上捕获UI界面,然后将它们以并排对比表格的形式展示。
Arguments
参数
- - PR number and optional description of what to screenshot (e.g. pages/routes to capture)
$ARGUMENTS
- - PR编号以及可选的截图内容描述(例如:要捕获的页面/路由)
$ARGUMENTS
Execution Steps
执行步骤
1. Parse Arguments & Get Repo Info
1. 解析参数并获取仓库信息
bash
undefinedbash
undefinedGet current repo info
Get current repo info
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
Get PR info (base branch, head branch, title, body)
Get PR info (base branch, head branch, title, body)
gh pr view <PR_NUMBER> --json baseRefName,headRefName,title,body
gh pr view <PR_NUMBER> --json baseRefName,headRefName,title,body
Save branch names
Save branch names
BASE_BRANCH=<baseRefName> # e.g. main
HEAD_BRANCH=<headRefName> # e.g. feature/new-ui
undefinedBASE_BRANCH=<baseRefName> # e.g. main
HEAD_BRANCH=<headRefName> # e.g. feature/new-ui
undefined2. Capture "Before" Screenshots (Base Branch)
2. 捕获"变更前"截图(基础分支)
bash
undefinedbash
undefinedStash any uncommitted changes, then checkout the base branch
Stash any uncommitted changes, then checkout the base branch
git stash
git checkout $BASE_BRANCH
git stash
git checkout $BASE_BRANCH
Install dependencies (in case they differ)
Install dependencies (in case they differ)
pnpm install
pnpm install
Start dev server
Start dev server
pnpm dev &
DEV_PID=$!
sleep 5
pnpm dev &
DEV_PID=$!
sleep 5
Create screenshot directories
Create screenshot directories
mkdir -p docs/screenshot/before docs/screenshot/after
mkdir -p docs/screenshot/before docs/screenshot/after
Open the page(s) to screenshot
Open the page(s) to screenshot
agent-browser open "http://localhost:3000/path/to/feature"
sleep 2
agent-browser open "http://localhost:3000/path/to/feature"
sleep 2
Login if needed (check CLAUDE.md for credentials)
Login if needed (check CLAUDE.md for credentials)
agent-browser snapshot -i
agent-browser fill @e1 "email"
agent-browser fill @e2 "password"
agent-browser click @e3
agent-browser snapshot -i
agent-browser fill @e1 "email"
agent-browser fill @e2 "password"
agent-browser click @e3
Navigate to the relevant page and take screenshot(s)
Navigate to the relevant page and take screenshot(s)
agent-browser screenshot docs/screenshot/before/feature-overview.png
agent-browser screenshot docs/screenshot/before/feature-detail.png
agent-browser screenshot docs/screenshot/before/feature-overview.png
agent-browser screenshot docs/screenshot/before/feature-detail.png
Stop dev server and close browser
Stop dev server and close browser
agent-browser close
kill $DEV_PID 2>/dev/null || true
pkill -f "next dev" || true
undefinedagent-browser close
kill $DEV_PID 2>/dev/null || true
pkill -f "next dev" || true
undefined3. Capture "After" Screenshots (PR Branch)
3. 捕获"变更后"截图(PR分支)
bash
undefinedbash
undefinedCheckout the PR branch
Checkout the PR branch
git checkout $HEAD_BRANCH
git stash pop || true
git checkout $HEAD_BRANCH
git stash pop || true
Install dependencies
Install dependencies
pnpm install
pnpm install
Start dev server
Start dev server
pnpm dev &
DEV_PID=$!
sleep 5
pnpm dev &
DEV_PID=$!
sleep 5
Open the same page(s)
Open the same page(s)
agent-browser open "http://localhost:3000/path/to/feature"
sleep 2
agent-browser open "http://localhost:3000/path/to/feature"
sleep 2
Login if needed (same steps as before)
Login if needed (same steps as before)
agent-browser snapshot -i
agent-browser fill @e1 "email"
agent-browser fill @e2 "password"
agent-browser click @e3
agent-browser snapshot -i
agent-browser fill @e1 "email"
agent-browser fill @e2 "password"
agent-browser click @e3
Navigate to the same page and take screenshot(s)
Navigate to the same page and take screenshot(s)
agent-browser screenshot docs/screenshot/after/feature-overview.png
agent-browser screenshot docs/screenshot/after/feature-detail.png
agent-browser screenshot docs/screenshot/after/feature-overview.png
agent-browser screenshot docs/screenshot/after/feature-detail.png
Stop dev server and close browser
Stop dev server and close browser
agent-browser close
kill $DEV_PID 2>/dev/null || true
pkill -f "next dev" || true
undefinedagent-browser close
kill $DEV_PID 2>/dev/null || true
pkill -f "next dev" || true
undefined4. Screenshot Naming Convention
4. 截图命名规范
Use matching filenames in and so the comparison table is easy to construct:
before/after/docs/screenshot/
├── before/
│ ├── feature-overview.png
│ ├── feature-detail.png
│ └── feature-empty.png
└── after/
├── feature-overview.png
├── feature-detail.png
└── feature-empty.pngNaming ideas:
- — main view
feature-overview.png - — expanded/detailed view
feature-detail.png - — empty state
feature-empty.png - — loading state
feature-loading.png - — mobile viewport
feature-mobile.png
在和目录中使用匹配的文件名,以便轻松构建对比表格:
before/after/docs/screenshot/
├── before/
│ ├── feature-overview.png
│ ├── feature-detail.png
│ └── feature-empty.png
└── after/
├── feature-overview.png
├── feature-detail.png
└── feature-empty.png命名建议:
- — 主视图
feature-overview.png - — 展开/详情视图
feature-detail.png - — 空状态
feature-empty.png - — 加载状态
feature-loading.png - — 移动端视口
feature-mobile.png
5. Commit & Push
5. 提交并推送
bash
git add docs/screenshot/
git commit -m "$(cat <<'EOF'
docs: add before/after screenshots for [feature]
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
EOF
)"
git pushbash
git add docs/screenshot/
git commit -m "$(cat <<'EOF'
docs: add before/after screenshots for [feature]
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
EOF
)"
git push6. Update PR Body with Before/After Comparison Table
6. 更新PR正文,添加前后对比表格
IMPORTANT: Use GitHub CDN URL format with :
?raw=truehttps://github.com/<REPO>/blob/<BRANCH>/docs/screenshot/<before|after>/<filename>.png?raw=trueWhere is the from step 1 and is the PR head branch.
<REPO>nameWithOwner<BRANCH>Update PR body with a comparison table:
bash
gh pr edit <PR_NUMBER> --body "$(cat <<'EOF'重要提示:使用带的GitHub CDN链接格式:
?raw=truehttps://github.com/<REPO>/blob/<BRANCH>/docs/screenshot/<before|after>/<filename>.png?raw=true其中是步骤1中获取的,是PR的头部分支。
<REPO>nameWithOwner<BRANCH>使用对比表格更新PR正文:
bash
gh pr edit <PR_NUMBER> --body "$(cat <<'EOF'PR Title
PR Title
Summary
Summary
[existing summary]
[existing summary]
Screenshots
Screenshots
Feature Overview
Feature Overview
| Before | After |
|---|---|
![]() | ![]() |
| Before | After |
|---|---|
![]() | ![]() |
Detail View
Detail View
| Before | After |
|---|---|
![]() | ![]() |
[rest of PR body]
EOF
)"
**Add one table per page/state you screenshot.** Each table has a single row with the before image on the left and the after image on the right.| Before | After |
|---|---|
![]() | ![]() |
[rest of PR body]
EOF
)"
**每个页面/状态添加一个表格**。每个表格包含一行,左侧是变更前的图片,右侧是变更后的图片。7. Clean Up
7. 清理
bash
agent-browser close
pkill -f "next dev" || true
git checkout $HEAD_BRANCHbash
agent-browser close
pkill -f "next dev" || true
git checkout $HEAD_BRANCHGitHub CDN URL Format
GitHub CDN链接格式
Always use this exact format for images to render in GitHub:
https://github.com/OWNER/REPO/blob/BRANCH/path/to/image.png?raw=true- OWNER/REPO: Get from
gh repo view --json nameWithOwner -q .nameWithOwner - BRANCH: The PR head branch name (get from )
gh pr view - ?raw=true: Required suffix for images to display
请始终使用以下精确格式的图片链接以确保在GitHub中正常显示:
https://github.com/OWNER/REPO/blob/BRANCH/path/to/image.png?raw=true- OWNER/REPO:从获取
gh repo view --json nameWithOwner -q .nameWithOwner - BRANCH:PR的头部分支名称(从获取)
gh pr view - ?raw=true:图片正常显示所需的必填后缀
Authentication
身份验证
If the app requires login, check the project's for test credentials.
CLAUDE.md如果应用需要登录,请查看项目的文件获取测试凭据。
CLAUDE.mdTips
提示
- Consistency is key: screenshot the exact same pages/viewports/states on both branches so the comparison is meaningful
- Use to see all open tabs
agent-browser tab list - Use to switch tabs
agent-browser tab N - For elements not in snapshot, use CSS selectors:
agent-browser click "button.submit" - Scroll with:
agent-browser scroll down 500 - For responsive comparisons, resize the viewport:
agent-browser eval "window.resizeTo(375, 812)" - If a page doesn't exist on the base branch (new page), skip the "before" screenshot and note it in the PR body as New Page
- 一致性是关键:在两个分支上捕获完全相同的页面/视口/状态,这样对比才有意义
- 使用查看所有打开的标签页
agent-browser tab list - 使用切换标签页
agent-browser tab N - 对于快照中未包含的元素,使用CSS选择器:
agent-browser click "button.submit" - 滚动页面:
agent-browser scroll down 500 - 如需响应式对比,调整视口大小:
agent-browser eval "window.resizeTo(375, 812)" - 如果基础分支上不存在某个页面(新增页面),则跳过"变更前"截图,并在PR正文中注明为新增页面



