Removing cookie banners from a screenshot
A capture with a consent dialog across it is a capture of the consent dialog. Four passes run on every request by default — here is what each one does, and the three cases where they still lose.
Why you cannot just crop it
Consent banners are positioned fixed or sticky. They
are pinned to the viewport, not to a place on the page, so they sit over
whatever is beneath them at the moment the shutter opens — usually the
content you wanted. Three further reasons cropping fails:
- They re-render. A React banner removed from the DOM is often put back on the next render pass, which may be after your crop logic ran.
- They lock scrolling. Many set
overflow: hiddenon the body, so a full-page capture gets one viewport and stops. - Video has no crop. On a scrolling video the banner travels with the viewport for the whole clip. There is no frame to crop.
What actually runs, in four passes
In order, stopping as soon as the page is clean. Each pass exists because the one before it failed on a real site.
Pass 1 — click the real button
Eight selectors keyed to the big consent platforms by id: OneTrust's
#onetrust-accept-btn-handler, Cookiebot's dialog button, and their
peers. Dismissing a banner proves better than hiding one, because
the page then reflows exactly as a visitor would see it — no scroll lock
left set, no dimmed backdrop still painted over the content.
Pass 1b — click it by its label instead
Every selector above keys off an id or a class, which works on platforms whose
markup is stable and named, and fails completely on a hand-rolled banner in a
framework that hashes its class names. vercel.com ships exactly
that: its “Accept all” button sat through every markup pass while
the banner stayed in the capture.
So eight button labels are matched as a fallback — and only inside a
fixed or sticky ancestor. That restriction is
deliberate. A cookie banner is pinned to the viewport; a bare
“Accept” in ordinary page flow is far more likely to be a form
nobody asked us to submit. Clicking the wrong button on someone
else’s site is worse than leaving a banner in the picture.
Pass 2 — dismiss what is left
Newsletter modals, app-install prompts and chat widgets are not consent dialogs and have no Accept button. This pass goes after their close controls.
Pass 3 — a stylesheet that keeps them hidden
Injected CSS survives a re-render in a way a DOM removal does not: the element
can come back, but it comes back hidden. This is the pass a site can
refuse. A Content-Security-Policy of
style-src 'self' blocks an injected stylesheet outright, and on
22 November 2026 that refusal was returning 500s to our own
callers until we made it non-fatal. It is now a warning in the log and the
capture continues, because pass 4 hides the same elements by a route CSP does
not police.
Pass 4 — remove the remainder from the DOM
126 selectors, covering the consent frameworks and the common popup patterns.
It carries a guard that refuses to touch <body>,
<html>, or any element containing the body — because
most of those selectors are substring matchers like
[class*="cookie-bar"], and a page whose body class happens to
contain one of those words matches. That guard was written after the list
deleted urlbox.com’s entire <body>.
Ad frames are blocked before they load
block_ads works at the request layer, not the style layer: the
requests are aborted, so the frames never render. The domain list derives from
EasyList and covers Google’s ad stack, Amazon, the major exchanges and
SSPs, and the usual data brokers.
The side effect is worth more than the tidiness. Most late layout shift in a capture comes from an ad slot resizing after the screenshot was taken, and a slot that never loads cannot resize.
The options
| Option | Default | What it does |
|---|---|---|
remove_popups | true | The four passes above |
block_ads | true | Aborts ad and tracker requests |
css | empty | Your own CSS, up to 10,000 characters, injected before capture |
wait_for_selector | none | Wait for real content before shooting, after the banner is gone |
For whatever survives
A site with a bespoke overlay will eventually beat a generic selector list.
The css field is the escape hatch, and it runs on every capture
type including video:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "x-api-key: $GETSNAP_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"full_page": true,
"css": ".cookie-bar, .chat-widget, .promo-banner { display: none !important }",
"wait_for_selector": ".hero"
}'
Pair it with wait_for_selector. Hiding the banner and shooting
immediately can catch the page mid-reflow; waiting for something real means
waiting for the layout to settle.
Where this still loses
Three cases, honestly:
- Shadow DOM. A dialog inside a shadow root is not reachable
by
querySelectorAll, so no selector list finds it — ours or yours. - A strict Content-Security-Policy. It can refuse the injected stylesheet, as described in pass 3. The DOM pass still runs, but anything that re-renders afterwards comes back visible.
- Interstitials that are the page. An age gate, a paywall or a login wall is not an overlay on the content; it is what the server sent. There is nothing underneath to reveal, and a tool that pretended otherwise would be lying to you.
Frequently asked questions
Do I have to turn cookie-banner removal on?
No. remove_popups and block_ads both default to
true on every capture endpoint. The useful behaviour is the
default rather than a flag you have to discover.
Does it click “Accept all” on my behalf?
It tries to, because a dismissed banner leaves the page reflowed the way a visitor would see it. Matching by button text is restricted to elements inside a fixed or sticky ancestor, for the reason given in pass 1b.
Why is the banner still in my capture?
Usually a shadow root, a Content-Security-Policy, or an
interstitial that is the page. The three cases above say which is which, and
the css field handles the first two.
Does blocking ads make captures faster?
Usually, because the requests are aborted rather than hidden. It also makes the layout settle sooner, which is the part that changes what the picture looks like.
Try it on the page that keeps beating you
No account, no card. If the banner survives here too, at least you know.
Open the free screenshot tool