How to take screenshots without cookie banners
Why consent pop-ups ruin screenshots, how filter lists and consent clicks remove them, and how to hide anything that slips through.
6 min read
If you’ve ever automated screenshots, you’ve seen it: half of every image is a consent banner. Since GDPR and the ePrivacy rules, most sites show one to every new visitor, and a headless browser is always a new visitor. This explainer covers why simple fixes don’t work, how shotsmith removes banners, and what to do about the ones that slip through.
Why it’s harder than it looks
- Hiding the banner isn’t enough. Many consent tools also lock scrolling, dim the page behind an overlay, or hold back content until you choose. Hide only the banner and you can get a grey, unscrollable page.
- There are hundreds of consent tools. OneTrust, Cookiebot, Didomi, Usercentrics, Quantcast and many in-house banners, each with different markup that changes over time.
- Some only go away once answered. The page renders differently after consent is given, so the “clean” version of the page only exists after a click.
- Blocking the script can break the page. Some sites won’t finish loading if their consent tool fails to load.
How shotsmith removes them
With block_cookie_banners=true, three things happen, in order:
- Filter lists. Community-maintained cosmetic filter lists, with tens of thousands of rules for known consent tools, hide banners the moment they appear, before they’re ever drawn.
- Consent click-through. For banners that only disappear once answered, the page’s own “accept” button is clicked, so the site renders its post-consent state, as a returning visitor would see it.
- Cleanup. Any fixed overlay that still looks like a consent prompt is hidden, and scrolling is unlocked if the banner had locked it.
// npm install @shotsmith/sdk
import { Shotsmith, TakeOptions } from '@shotsmith/sdk';
import { writeFile } from 'node:fs/promises';
const shotsmith = new Shotsmith({
accessKey: 'YOUR_ACCESS_KEY',
});
const options = TakeOptions.url('https://shotsmith.dev/sample')
.blockCookieBanners()
.blockChats()
.format('png');
await writeFile('capture.png', await shotsmith.take(options));
<?php
// composer require shotsmith/shotsmith-php
require 'vendor/autoload.php';
use Shotsmith\Client;
use Shotsmith\Options\TakeOptions;
$shotsmith = new Client('YOUR_ACCESS_KEY');
$options = TakeOptions::url('https://shotsmith.dev/sample')
->blockCookieBanners()
->blockChats()
->format('png');
file_put_contents('capture.png', $shotsmith->take($options));
// In Laravel: Shotsmith::take($options) with SHOTSMITH_ACCESS_KEY in .env
curl -G "https://shotsmith.dev/v1/take" \ --data-urlencode "access_key=YOUR_ACCESS_KEY" \ --data-urlencode "url=https://shotsmith.dev/sample" \ --data-urlencode "block_cookie_banners=true" \ --data-urlencode "block_chats=true" \ --data-urlencode "format=png" \ -o capture.png
import { writeFile } from 'node:fs/promises';
const params = new URLSearchParams({
access_key: 'YOUR_ACCESS_KEY',
url: 'https://shotsmith.dev/sample',
block_cookie_banners: 'true',
block_chats: 'true',
format: 'png',
});
const res = await fetch(`https://shotsmith.dev/v1/take?${params}`);
if (!res.ok) throw new Error((await res.json()).error_message);
await writeFile('capture.png', Buffer.from(await res.arrayBuffer()));
import urllib.request
from urllib.parse import urlencode
params = {
"access_key": "YOUR_ACCESS_KEY",
"url": "https://shotsmith.dev/sample",
"block_cookie_banners": "true",
"block_chats": "true",
"format": "png"
}
url = "https://shotsmith.dev/v1/take?" + urlencode(params, doseq=True)
# Raises urllib.error.HTTPError on a 4xx/5xx response
with urllib.request.urlopen(url, timeout=120) as res, open("capture.png", "wb") as f:
f.write(res.read())
<?php
$query = http_build_query([
'access_key' => 'YOUR_ACCESS_KEY',
'url' => 'https://shotsmith.dev/sample',
'block_cookie_banners' => 'true',
'block_chats' => 'true',
'format' => 'png',
], '', '&', PHP_QUERY_RFC3986);
$ch = curl_init('https://shotsmith.dev/v1/take?' . $query);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status !== 200) {
throw new RuntimeException(json_decode($body, true)['error_message'] ?? "HTTP {$status}");
}
file_put_contents('capture.png', $body);
package main
import (
"io"
"net/http"
"os"
)
func main() {
res, err := http.Get("https://shotsmith.dev/v1/take?access_key=YOUR_ACCESS_KEY&url=https%3A%2F%2Fshotsmith.dev%2Fsample&block_cookie_banners=true&block_chats=true&format=png")
if err != nil {
panic(err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
body, _ := io.ReadAll(res.Body)
panic(string(body))
}
out, err := os.Create("capture.png")
if err != nil {
panic(err)
}
defer out.Close()
io.Copy(out, res.Body)
}
require "net/http"
require "uri"
uri = URI("https://shotsmith.dev/v1/take")
uri.query = URI.encode_www_form([
["access_key", "YOUR_ACCESS_KEY"],
["url", "https://shotsmith.dev/sample"],
["block_cookie_banners", "true"],
["block_chats", "true"],
["format", "png"]
])
res = Net::HTTP.get_response(uri)
raise res.body unless res.is_a?(Net::HTTPSuccess)
File.binwrite("capture.png", res.body)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
public class Capture {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder(URI.create(
"https://shotsmith.dev/v1/take?access_key=YOUR_ACCESS_KEY&url=https%3A%2F%2Fshotsmith.dev%2Fsample&block_cookie_banners=true&block_chats=true&format=png"
)).build();
var res = client.send(request, HttpResponse.BodyHandlers.ofFile(Path.of("capture.png")));
if (res.statusCode() != 200) {
throw new RuntimeException("HTTP " + res.statusCode());
}
}
}
using System;
using System.IO;
using System.Net.Http;
using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(120) };
// Throws HttpRequestException on a 4xx/5xx response
var bytes = await http.GetByteArrayAsync(
"https://shotsmith.dev/v1/take?access_key=YOUR_ACCESS_KEY&url=https%3A%2F%2Fshotsmith.dev%2Fsample&block_cookie_banners=true&block_chats=true&format=png"
);
await File.WriteAllBytesAsync("capture.png", bytes);
When something slips through
block_banners_by_heuristics=trueadds an extra pass for banners the lists don’t know. It’s off by default because it can occasionally hide real content, such as a sticky promotional bar.hide_selectorshides any element by CSS selector. Inspect the banner in your browser’s DevTools and pass its selector, for example#consent-popup.clickclicks an element before capturing, for banners that need a specific button pressed.stylesinjects your own CSS for anything else.
Other things to remove
Consent banners are rarely the only clutter. block_chats removes chat bubbles (Intercom, Crisp, Drift, Zendesk, HubSpot and more), block_ads blocks ad networks and collapses empty ad slots, and block_trackers stops analytics scripts, which also tends to make pages load faster.
A note on consent
Removing a banner from a screenshot is about capturing the page’s content cleanly; it doesn’t give consent on anyone’s behalf. Each render runs in a fresh, isolated browser context, and no cookies or storage carry over between captures.