Detecting a blank screenshot, and the cases that look blank but are not

A white frame returned as 200 OK is the worst failure a screenshot API has. Two signals that must agree, why bytes-per-pixel only works on one configuration, and the captcha that reads as zero characters while showing a full page.

The worst thing a screenshot API can do is succeed incorrectly. A bot wall, a page that needed JavaScript you blocked, or a render that finished too early all produce a blank white frame, a 200 OK, and a valid PNG. Your pipeline files it as a success, and nobody notices for a month.

Screenshotline flags those in a response header, X-Blank-Suspected, and fail_on_blank=true turns the flag into a 502. Getting the detector to be useful took three corrections, and each one came from a page that lied to it.

Two signals, because each one alone is wrong

const domBlank = content.textLength < 20 && content.images === 0 && content.elements < 15;
const visuallyBlank = calibrated && bytesPerPixel < 0.008 && content.textLength < 400;
const blankSuspected =
  detectorApplies &&
  options.format !== 'pdf' &&
  (visuallyBlank || (domBlank && (!calibrated || bytesPerPixel < 0.03)));

The DOM signal asks whether the page has anything in it. On its own it flags legitimately sparse pages: badssl.com is one heading on a coloured background and is exactly what the user asked for.

The pixel signal asks how much the encoded image weighs per pixel, since a uniform image compresses to almost nothing. On its own it flags any simple page.

Neither is trustworthy alone, so a capture is only suspected blank when both agree, or when the visual signal is extreme.

calibrated is doing more work than it looks

Bytes-per-pixel measures the encoding as much as the page. A 3840x4320 capture of a small page is mostly white whether or not anything went wrong. A quality-1 JPEG is tiny whatever it shows. A WebP at the same visual quality weighs differently from a PNG.

So the pixel thresholds only apply to the configuration they were measured on: a PNG at a normal viewport. Outside that, the detector falls back to the DOM signal alone. Thresholds carry their measurement conditions with them, or they are not thresholds, they are superstitions.

detectorApplies: not every 200 is HTML

A successful response that is not HTML is legitimately sparse. Chrome's own JSON viewer, its image viewer, an XML tree: all of them have almost no DOM and almost no text, because the content is not in the DOM.

A JSON endpoint was being flagged as a blank capture until the detector learned to check the upstream content type first. PDFs are excluded for the same reason, since the pixel heuristic means nothing there.

The pages that look blank and are not

Three cases taught me the limits of any automated check.

reuters.com is a captcha wall whose visible text lives inside an iframe. X-Text-Length reads 0, so every text-based rule calls it blank, and the image shows a full page with a challenge on it. Not blank. Not a success either, but a different failure.

badssl.com and pages like it are genuinely one heading on a colour. Blank by every DOM measure, correct by every other one.

nytimes.com swings between 80 KB and 650 KB depending on how much of its skeleton has hydrated. That is page timing rather than blankness, and delay is the parameter for it.

Which is why the flag is advisory by default. The header says "this looks blank" and the customer decides, because only the customer knows whether a sparse page is what they asked for.

Blankness as a billing rule, and its limit

Flagged captures are not billed, up to 10% of the plan's monthly volume with a minimum of 50. The cap exists because blankness can be gamed: a caller who controls the target page can serve an empty document and render for free forever. Beyond the cap a flagged capture bills like any other, because the image was still delivered.

An earlier version had no cap at all, and the flag could be forced on real content through a narrow selector, a huge viewport or a quality-1 JPEG. Any rule that makes something free becomes an input an attacker controls.

The benchmark rule that goes with it

A detector that only runs in production is a detector nobody checks. In the 202-site suite, pages known to be blank for everyone are marked blankOk one at a time, after I have looked at them. A blank frame on any other page fails the whole run with a non-zero exit, so a silent regression cannot pass a CI job that only checks the status code.

What to copy

  1. Decide what "wrong but successful" looks like in your domain, then detect it explicitly. It will not show up in your error rate.
  2. Use two independent signals and require agreement. Every single signal has a page that defeats it.
  3. Tie any threshold to the configuration it was measured on, and fall back when you leave that configuration.
  4. Check the content type before applying a content heuristic.
  5. Report it rather than deciding for the user, and let them opt into failure.
  6. Cap anything you make free, because the person who controls the input will find it.

The detector is in src/render.js and the benchmark rules that keep it honest are in the post about the suite. Every response from the hosted API carries X-Blank-Suspected, on the free tier too.

Get a free key — 500 renders a month Try it without signing up

More from the blog