full-page-screenshot
alirezarezvani/claude-skills
利用 Chrome DevTools 協定擷取任何網頁的全頁螢幕截圖,無需任何外部依賴項,即可處理單頁應用程式(SPA)、延遲載入的圖片以及極長的網頁。
...展開全部全頁截圖
透過 Chrome DevTools 協定擷取任何網頁的整頁螢幕截圖。產生單一 PNG 檔案,其中包含所有內容——即使是需要捲動才能看到的區域也不例外。除了 Node.js 22 以上版本以及已啟用遠端除錯功能的 Chrome 瀏覽器外,無需任何外部依賴項。
先決條件
- Node.js 22 以上(使用內建
WebSocket) - Chrome/Chromium 且已啟用遠端除錯功能
檢查環境是否就緒:
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" --check
若 Chrome 檢查失敗,請指示使用者開啟 chrome://inspect/#remote-debugging 並啟用「允許對此瀏覽器實例進行遠端除錯」。
工作流程
選項 A:擷取已開啟的分頁畫面(建議用於已驗證的頁面)
- 列出可用分頁:
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" --list
- 根據標題/網址識別目標分頁,然後擷取畫面:
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" /tmp/screenshot.png --width 1200 --dpr 1
選項 B:擷取 URL 畫面(開啟背景分頁、擷取畫面、關閉分頁)
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" --url "https://example.com" /tmp/screenshot.png --width 1200 --dpr 1 --wait 15000
注意:
--url此模式會建立一個背景分頁。需要驗證的頁面(單一登入、登入牆)應改用選項 A。
參數
| 參數 | 說明 | 預設值 |
|---|---|---|
output |
輸出 PNG 檔案路徑 | /tmp/screenshot.png |
--width |
視口寬度(以 CSS 像素為單位)(文章:1200,儀表板:1440-1920) | 1200 |
--dpr |
裝置像素比例(2 = Retina,但檔案大小為 4 倍) | 1 |
--wait |
頁面載入超時(以毫秒為單位)(--url 僅限此模式) |
15000 |
--css |
擷取前注入的自訂 CSS(例如:隱藏元素) | — |
驗證輸出
# macOS
sips -g pixelWidth -g pixelHeight /tmp/screenshot.png
# Linux
file /tmp/screenshot.png
核心功能
SPA 捲動容器擴展 — 偵測
overflow-y: auto/scroll容器,捲動其中以觸發延遲載入,隨後移除溢出限制(包括 Tailwindh-[calc(...)]),使所有內容能在單次渲染中完成。DOM 穩定性檢測 — 在
readyState=complete,持續監控 DOM 元素數量直至其趨於穩定。此舉可確保單頁應用程式(SPA)框架完成動態內容的渲染。懶加載觸發 — 逐步捲動檢視窗以觸發
IntersectionObserver回調函式,接著等待所有元素完成載入。針對極高頁面的分塊擷取 — 超過 16,000px 的頁面將被分割為 8,000px 的區塊進行擷取,並透過 Python PIL 自動拼接。若無法使用 PIL,則回退至分別儲存各區塊。
Chrome 自動偵測 — 讀取
DevToolsActivePort檔案以查找除錯埠。若無法讀取該檔案,則改為探測 9222、9229、9333 埠。CDP 代理備用方案 — 當 CDP 代理持有瀏覽器的 WebSocket 連線時,腳本會改用代理 API 端點 (
/eval,/screenshot,/scroll)進行擷取。
運作原理
1. Discover Chrome debugging port
2. Connect via WebSocket (CDP)
3. Attach to target / create background tab
4. Set viewport width via Emulation domain
5. Wait: readyState + DOM stability
6. Detect & expand scroll containers
7. Scroll through page (trigger lazy-load)
8. Wait for images to complete
9. Measure final content height
10. Page.captureScreenshot (or tiled capture)
11. Stitch tiles if needed (PIL)
12. Restore viewport, detach, clean up
反模式
| 切勿 | 應採取以下做法 |
|---|---|
請勿 --dpr 2 高度超過 10,000px 的頁面 |
請使用 --dpr 1 以避免 Chrome 記憶體問題 |
請使用 --url 於已驗證身分/單一登入(SSO)頁面 |
請在 --list 在用戶已登入的分頁上使用 + targetId |
將 --wait 對於單頁應用程式 (SPA),請將此數值設定為 5000 以下 |
單頁應用程式(SPA)需要時間擷取資料並渲染;請設定為 10000-15000 |
無需檢查即可擷取 --check |
請務必確認 Chrome 除錯功能是否可用 |
| 為所有頁面硬編碼視口寬度 | 文章頁面使用 1200,儀表板/表格使用 1440 以上 |
| 跳過輸出驗證 | 務必使用以下方式進行驗證 sips 或 file 在擷取後執行 |
疑難排解
| 症狀 | 原因 | 解決方法 |
|---|---|---|
| 「找不到 Chrome 除錯埠」 | 未啟用遠端除錯 | 開啟 chrome://inspect/#remote-debugging,並啟用該功能 |
| 「WebSocket 連線超時」 | CDP 代理伺服器正在維持連線 | 腳本自動回退至代理 API |
| 空白/白色螢幕截圖 | 頁面尚未載入 | 增加 --wait 值 |
| 底部內容被截斷 | 捲動容器未展開 | 腳本會自動處理此情況;若問題持續,請提交問題報告 |
| 記憶體不足 | 頁面過高 + 高 DPR | 將 --dpr 至 1 及/或將 --width |
| 「PIL 無法用於拼接」 | 未安裝 Python Pillow | 請使用 pip3 install Pillow 或接受獨立的圖塊檔案 |
相關參照
engineering/browser-automation— 透過 CDP/Playwright 實現的通用瀏覽器自動化模式engineering/performance-profiler— 可作為視覺擷取輔助的效能分析
---
name: full-page-screenshot
description: Capture full-page screenshots of any web page using Chrome DevTools Protocol, handling SPAs, lazy-loaded images, and very tall pages with zero external dependencies.
---
# Full Page Screenshot
Capture a full-page screenshot of any web page via Chrome DevTools Protocol. Produces a single PNG that includes all content — even portions that require scrolling. Zero external dependencies beyond Node.js 22+ and Chrome with remote debugging enabled.
## Prerequisites
- **Node.js 22+** (uses built-in `WebSocket`)
- **Chrome/Chromium** with remote debugging enabled
Check environment readiness:
```bash
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" --check
```
If Chrome check fails, instruct user to open `chrome://inspect/#remote-debugging` and enable **"Allow remote debugging for this browser instance"**.
## Workflow
### Option A: Screenshot an already-open tab (recommended for authenticated pages)
1. List available tabs:
```bash
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" --list
```
2. Identify the target by title/URL, then capture:
```bash
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" <targetId> /tmp/screenshot.png --width 1200 --dpr 1
```
### Option B: Screenshot a URL (opens a background tab, captures, closes)
```bash
node "${SKILL_DIR}/scripts/full-page-screenshot.mjs" --url "https://example.com" /tmp/screenshot.png --width 1200 --dpr 1 --wait 15000
```
> **Note:** `--url` mode creates a background tab. Pages requiring authentication (SSO, login walls) should use Option A instead.
### Parameters
| Parameter | Description | Default |
|-----------|-------------|---------|
| `output` | Output PNG file path | `/tmp/screenshot.png` |
| `--width` | Viewport width in CSS pixels (articles: 1200, dashboards: 1440-1920) | 1200 |
| `--dpr` | Device pixel ratio (2 = Retina, but 4x file size) | 1 |
| `--wait` | Page load timeout in ms (`--url` mode only) | 15000 |
| `--css` | Custom CSS to inject before capture (e.g., hide elements) | — |
### Verify Output
```bash
# macOS
sips -g pixelWidth -g pixelHeight /tmp/screenshot.png
# Linux
file /tmp/screenshot.png
```
## Core Capabilities
1. **SPA scroll container expansion** — Detects `overflow-y: auto/scroll` containers, scrolls through them to trigger lazy-loading, then removes overflow constraints (including Tailwind `h-[calc(...)]`) so all content renders in a single pass.
2. **DOM stability detection** — After `readyState=complete`, monitors DOM element count until it stabilizes. This ensures SPA frameworks finish rendering dynamic content.
3. **Lazy-load triggering** — Scrolls the viewport incrementally to fire `IntersectionObserver` callbacks, then waits for all `<img>` elements to complete loading.
4. **Tiled capture for very tall pages** — Pages exceeding 16,000px are captured in 8,000px tiles and automatically stitched using Python PIL. Falls back to saving tiles separately if PIL is unavailable.
5. **Auto-discovery of Chrome** — Reads `DevToolsActivePort` file to find the debugging port. Falls back to probing ports 9222, 9229, 9333.
6. **CDP Proxy fallback** — When a CDP proxy holds the browser WebSocket, the script falls back to proxy API endpoints (`/eval`, `/screenshot`, `/scroll`) for capture.
## How It Works
```
1. Discover Chrome debugging port
2. Connect via WebSocket (CDP)
3. Attach to target / create background tab
4. Set viewport width via Emulation domain
5. Wait: readyState + DOM stability
6. Detect & expand scroll containers
7. Scroll through page (trigger lazy-load)
8. Wait for images to complete
9. Measure final content height
10. Page.captureScreenshot (or tiled capture)
11. Stitch tiles if needed (PIL)
12. Restore viewport, detach, clean up
```
## Anti-Patterns
| Do NOT | Do instead |
|--------|-----------|
| Use `--dpr 2` on pages > 10,000px tall | Use `--dpr 1` to avoid Chrome memory issues |
| Use `--url` for authenticated/SSO pages | Use `--list` + targetId on a tab where user is logged in |
| Set `--wait` below 5000 for SPAs | SPAs need time to fetch data and render; use 10000-15000 |
| Capture without checking `--check` first | Always verify Chrome debugging is available |
| Hardcode viewport widths for all pages | Use 1200 for articles, 1440+ for dashboards/tables |
| Skip output verification | Always verify with `sips` or `file` command after capture |
## Troubleshooting
| Symptom | Cause | Fix |
|---------|-------|-----|
| "Cannot find Chrome debugging port" | Remote debugging not enabled | Open `chrome://inspect/#remote-debugging`, enable it |
| "WebSocket connection timeout" | CDP proxy holding the connection | Script auto-falls back to proxy API |
| Blank/white screenshot | Page not loaded yet | Increase `--wait` value |
| Truncated at bottom | Scroll container not expanded | Script handles this automatically; file an issue if it persists |
| Out of memory | Very tall page + high DPR | Reduce `--dpr` to 1 and/or reduce `--width` |
| "PIL not available for stitching" | Python Pillow not installed | Install with `pip3 install Pillow` or accept separate tile files |
## Cross-References
- [`engineering/browser-automation`](../browser-automation/SKILL.md) — General browser automation patterns via CDP/Playwright
- [`engineering/performance-profiler`](../performance-profiler/SKILL.md) — Performance analysis that may complement visual captures
安裝 full-page-screenshot
請下載並將技能檔案解壓縮至您的 .claude/skills/ 目錄中。
下載 ZIP複製儲存庫並將技能檔案複製到您的專案中。
git clone https://github.com/alirezarezvani/claude-skills/tree/main/engineering/skills/full-page-screenshot # Copy SKILL.md to your .claude/skills/ directory
複製





首頁
