tags: webdev, testing, cicd, screenshots
Had a pretty standard setup: Puppeteer in a Docker container, running inside GitHub Actions, taking screenshots for visual regression tests. It worked. Mostly.
The problems were always the same:
- Chrome would randomly crash on larger pages, especially SPAs with heavy JS
- Memory usage was unpredictable. Some runs needed 2GB, others 512MB
- Font rendering differed between local and CI because of missing system fonts
- The Docker image was 1.2GB and took 45 seconds just to pull
I spent way too long tweaking launch flags. `--disable-dev-shm-usage`, `--no-sandbox`, custom viewport hacks. Every few weeks something else would break.
What I switched to
Moved the screenshot step to an API call. One HTTP request, get back a PNG or WebP. The rendering happens on someone else's infrastructure with consistent fonts and consistent Chrome versions.
```javascript const response = await fetch('https://screenshotrun.com/api/screenshot', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_KEY' }, body: JSON.stringify({ url: 'https://myapp.com/dashboard', viewport: { width: 1280, height: 720 }, format: 'webp', wait_for: '.dashboard-loaded' }) }); const screenshot = await response.buffer(); ```
That `wait_for` selector was the thing that actually convinced me. My old Puppeteer setup used `waitForTimeout(3000)` which was both too long and not long enough depending on the page. The selector-based wait means it captures after the content is actually there.
What changed
CI runs dropped from ~4 minutes to under 90 seconds for the screenshot step. No more Docker image maintenance. No more debugging Chrome crashes in CI logs at 11pm.
The tradeoff is obvious — you're paying for API calls instead of compute time. For my use case (~200 screenshots per deploy, maybe 3 deploys a day) it costs less than the extra CI minutes did. Your math might be different if you're doing thousands.
One thing I didnt expect: the screenshots are more consistent now. Same Chrome version, same fonts, same rendering every time. Made the visual diff comparison actually useful instead of flagging phantom differences from font smoothing.
still keep Puppeteer locally for quick debugging. but for CI? not going back
Top comments (0)