π« The Pain Point
Boss: βGo to these 20 competitor websites and capture their homepage for our design meeting.β You: Open link β Wait load β Print Screen β Paste Paint β Crop. x 20. Some pages timeout, some have cookie popups.
π Agentic Solution
Headless Browser: Controls high-speed Chrome without drawing the UI (Headless), capturing pixels perfectly with smart error handling.
Key Features:
- Full Page: Captures the entire scrollable height, not just whatβs visible on screen.
- Smart Wait: Uses network idle detection instead of fixed timeouts.
- Error Recovery: Retries on timeout, logs failures, continues to next URL.
- Multi-Viewport: Supports desktop (1920x1080) and mobile (375x812) modes.
βοΈ Phase 1: Commander (Quick Fix)
For a quick investigation.
Prompt:
βI have
urls.txtwith one URL per line. Write a Node.js script using Puppeteer to:
- Smart Wait:
- Use
waitUntil: 'networkidle2'(at most 2 network connections for 500ms).- Set timeout to 30 seconds per page.
- Full Page Capture:
- Set viewport to 1920x1080 (Desktop).
- Scroll to bottom to trigger lazy-loaded images.
- Take
fullPage: truescreenshot.- Error Handling:
- If page fails (timeout, 404, SSL error), log to
error_log.txtand continue.- Retry once on timeout.
- Output: Save as
screenshots/{domain}.png.Print progress (e.g., βCaptured 1/50: example.comβ).β
Result: A folder of design references with full error handling.
ποΈ Phase 2: Architect (Permanent Tool)
For UI/UX Designers.
Engineering Prompt:
**Role:** Node.js Automation Engineer
**Task:** Create a "Batch Website Screenshot Tool".
**Requirements:**
1. **Input:** Read URLs from `urls.txt` (one per line).
2. **Engine:** Puppeteer (Headless Chrome).
3. **Features:**
* **Smart Wait:** `networkidle0` + 30s timeout per page.
* **Viewport Options:**
* Desktop: 1920x1080 (default)
* Mobile: 375x812 (via `--mobile` flag)
* **Full Page:** Scroll to trigger lazy-load, then capture.
* **Concurrency:** Process 3 URLs at a time (optional).
* **Error Handling:** Log failures to `error_log.txt`, continue to next.
* **Dark Mode:** Optional `--dark` flag to emulate prefers-color-scheme: dark.
4. **Deliverables:**
* `screenshot_advanced.js`
* `package.json`
* `run.bat` and `run.sh`
π§ Prompt Decoding
- NetworkIdle0: Websites have lazy-loading images. If you screenshot immediately, itβs blank. This command waits until β0 network connectionsβ are active, ensuring the site is fully loaded.
- Retry Logic: Real-world sites sometimes timeout. Instead of failing the whole batch, retry once and log failures.
π οΈ Instructions
- Install Node.js.
- Copy Prompt β Paste to AI β Run generated script.
- Edit
urls.txtβ Run β Checkscreenshots/folder.