Removing cookie banners from a screenshot, four years after GDPR

Consent banners arrive late, hide in shadow roots, and look exactly like the content next to them. The layered approach behind Screenshotline - block the vendor, watch the DOM, judge by structure - and the guards that stop it eating the page.

A screenshot of a cookie wall is useless to everyone. Removing one reliably is harder than it looks, because consent banners are built to survive exactly the tricks you would try first.

Screenshotline removes them in layers, and every layer exists because the one above it failed on a real site.

Layer 1: stop the script

The most reliable removal is the one where the banner never gets built. Known consent management platforms, Cookiebot, OneTrust, Quantcast and the rest, are blocked at the network layer by host.

When it works it is perfect: no banner, no race, no DOM surgery. It fails for every site that ships its own consent code, which is a lot of them.

Layer 2: watch the DOM, from before the page runs

The obvious approach for self-built banners is a sweep at capture time: find the dialog, remove it, take the picture. It loses a race it cannot see.

Many sites inject the banner late, after load, sometimes after the network goes quiet. nytimes.com is one. A sweep that runs at capture time is simply early.

So the watcher is installed before any of the page's own scripts run, and keeps sweeping as the DOM changes:

await page.evaluateOnNewDocument(COOKIE_OBSERVER_SCRIPT);

with a 50ms debounce, because a busy page mutates thousands of times and sweeping on every mutation is pure waste.

Layer 3: look inside shadow roots

querySelectorAll does not cross a shadow boundary. A consent dialog rendered inside a web component is invisible to any selector-based sweep, and the capture comes back as a full-page modal that the code swears it removed.

dw.com is the site that taught me this. The sweep now walks open shadow roots as well. Closed roots are unreachable by design, and nothing can be done about those.

The guard that matters more than any rule

Every removal rule can remove the wrong thing, and the failure is silent: a clean 200 with a hole in it where the article was.

The guard is content volume. Nothing carrying more than 1,500 characters of text is removed, whatever else it matches:

if (fullText.length > 1500) continue;

That rule exists because france24.com was losing about 1,200 characters of real article text to a heuristic that was otherwise behaving sensibly.

The second guard is structural rather than lexical. A consent banner is never the site's navigation. That sounds obvious; it was not obvious before the sweep ate apnews.com's entire header, 1,022 links and two <nav> elements, because a trending headline said "Girl Scout cookies" and the keyword test matched cookies while the action-word test matched ok inside c-o-ok-i-e-s.

Keyword rules are how you find candidates. Structural rules are what stop you deleting the page.

Promo bars, newsletter walls and donation overlays

The same machinery handles the rest of the interstitials, with its own shape test: a promo bar is short, edge-anchored and offers a dismissal, never most of the page. Those get swept repeatedly rather than once, because they are injected on timers long after everything else has settled.

Wikipedia's portal fundraising overlay is the one that needed naming explicitly. It fails the width, height and text guards simultaneously, which is to say it looks exactly like content by every generic measure. Some sites get a named rule, and a named rule is honest: it says this is a specific exception rather than pretending the general heuristic covers it.

The bug with no symptom

One more, because it is the best lesson in this codebase and it belongs wherever consent sweeps are discussed.

These scripts are built as JavaScript template literals so they can be injected with evaluateOnNewDocument. Inside a template literal, \b is not a word boundary. It collapses to a backspace character, U+0008.

So the regex meant to stop "ok" matching inside "cookies" compiled, inside the page, into a pattern that matched a backspace. It matched nothing. The heuristic that finds unknown banners was dead for two commits. Every test passed, every page rendered, and the apnews header "survived" the new guard only because nothing was being removed at all.

Double every backslash, and keep a test that scans injected scripts for control characters. \f, \v and \0 fail the same way, and \s quietly becomes the letter s.

What to copy

  1. Block the vendor script when you can. A banner that is never built cannot be missed.
  2. Install the observer before the page's own scripts, not at capture time.
  3. Walk open shadow roots, or component-built sites will defeat you silently.
  4. Guard by content volume. Never remove something carrying real text.
  5. Prefer structural rules to keyword rules. Navigation is not a consent banner, whatever the words say.
  6. Name your exceptions instead of widening a general rule until it eats something.

The sweeps are in src/blocking.js. block_cookie_banners=true is the default on the hosted API, and the whole renderer self-hosts with Docker if you would rather run it yourself.

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

More from the blog