DEV Community

Vitalii Holben
Vitalii Holben

Posted on

I replaced Selenium screenshots with a 3-line API call

Had a Selenium setup for taking screenshots in our CI pipeline. It worked, but maintaining it was a whole thing.

The Docker image was 800MB because it bundled Chromium. Build times were 4 minutes just for the screenshot step. And every few weeks something broke -- ChromeDriver version mismatch, a new Chrome flag that changed default behavior, font rendering differences between CI runners.

Spent more time babysitting the screenshot infrastructure than actually using the screenshots.

The switch

Ripped out the entire Selenium setup and replaced it with an HTTP call:

const resp = await fetch(
  `https://api.screenshotrun.com/capture?url=${encodeURIComponent(targetUrl)}&width=1440&format=png`,
  { headers: { "Authorization": `Bearer ${API_KEY}` } }
);
const buffer = await resp.arrayBuffer();
fs.writeFileSync("screenshot.png", Buffer.from(buffer));
Enter fullscreen mode Exit fullscreen mode

Thats it. No browser binary, no driver compatibility matrix, no 800MB Docker layer.

What changed

Build times dropped from 4 minutes to about 12 seconds for the screenshot step. The Docker image went from 800MB to 120MB. Zero maintenance on the rendering side -- thats someone elses problem now.

The screenshots are also more consistent. Same rendering environment every time, regardless of which CI runner picks up the job. No more "works on runner A, looks different on runner B" debugging sessions.

Tradeoffs

Costs money, obviously. For our volume (maybe 200 captures per day across staging and PR previews) its a few bucks a month. Way less than the engineer-hours I was spending on Selenium maintenance.

You also depend on an external service. If their API is down during your CI run, your build fails. Added a simple retry with 3 attempts and a 5-second backoff. Hasnt been an issue in practice but its worth knowing about.

If youre doing fewer than 50 screenshots a day and your Selenium setup is stable, probably not worth switching. But if youre fighting Chrome version mismatches every sprint like I was -- yeah, just use an API.

Top comments (0)