Shotfly

Guide

How to take screenshots without cookie banners

By the Shotfly team · Published 2026-12-01

Hide the banner with CSS once it appears, or click the site's own Reject button, then take the screenshot. Hiding needs no clicks; rejecting answers the site's question, so the site removes the banner itself. Neither works on a cookie wall, where the content stays locked until someone accepts.

Hide the banner with CSS

Many sites load their banner from a consent-management vendor, and each vendor puts it in a container with a fixed ID or class. Hide those containers, then catch home-made banners with a rule of thumb: a small fixed or sticky box that mentions cookies and contains a button. Save this as hide-consent.js:

hide-consent.js
// Runs inside the page: hides consent banners and their dark overlays.
export function hideConsent() {
  // Containers of widely used consent managers. Check them in DevTools: vendors rename things.
  const known = [
    '#onetrust-consent-sdk', // OneTrust
    '#CybotCookiebotDialog', // Cookiebot
    '#usercentrics-root', // Usercentrics
    '.qc-cmp2-container', // Quantcast Choice
    '#didomi-host', // Didomi
    '.fc-consent-root', // Google consent messages
    '[id^="sp_message_container"]', // Sourcepoint
    '.cky-consent-container', // CookieYes
  ]
  const style = document.createElement('style')
  style.textContent = `${known.join(', ')} { display: none !important }`
  document.head.append(style)

  // Banners from no known vendor: small fixed or sticky boxes with a button that mention cookies.
  for (const el of document.body.querySelectorAll('*')) {
    const { position } = getComputedStyle(el)
    if (position !== 'fixed' && position !== 'sticky') continue
    const text = el.textContent ?? ''
    if (text.length < 1500 && /cookie|consent/i.test(text) && el.querySelector('button, [role="button"]'))
      el.style.setProperty('display', 'none', 'important')
  }
}

Run it after the page loads, with a short wait, because consent scripts usually insert the banner after the load event:

import { chromium } from 'playwright'
import { hideConsent } from './hide-consent.js'

const url = process.argv[2]
const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } })
await page.goto(url, { waitUntil: 'load' })
await page.waitForTimeout(1500) // consent scripts often inject the banner after load
await page.evaluate(hideConsent)
await page.screenshot({ path: 'screenshot.png' })
await browser.close()

The rule of thumb can also match a sticky header that links to a cookie policy and has a menu button. Check the results on a few pages of a new site, and add the site's own selector to the list when the generic rules miss it.

Or click Reject

Clicking Reject gives the result a visitor who declines would see, and the site removes its own overlay. Find the button by its accessible name. The names below are English; add the wording of the sites you capture.

import { chromium } from 'playwright'

const url = process.argv[2]
const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } })
await page.goto(url, { waitUntil: 'load' })
const reject = page.getByRole('button', { name: /^(reject|decline|deny)( all)?( cookies)?$/i })
await reject.first().click({ timeout: 3000 }).catch(() => {}) // no banner, or no reject button
await page.waitForTimeout(500)
await page.screenshot({ path: 'screenshot.png' })
await browser.close()

Some consent managers draw the banner inside an iframe, and these lookups don't search iframes; in Playwright, use page.frameLocator() for those. Hiding the container with CSS works either way.

Avoid clicking Accept to get a clean image. Consent is a choice for a person to make, and accepting can load trackers and ads that change the page you capture.

A cookie wall covers the whole page and offers only Accept, or Accept and a paid subscription. Hiding the overlay sometimes reveals the content underneath; often the content never loaded, and the screenshot shows an empty page. Detect this case and report it as a failure instead of storing a dimmed or empty page.

With Shotfly

The block_cookie_banners parameter is on by default: Shotfly rejects or hides consent banners before it captures, and never clicks accept. Add hide_selectors for anything it misses. If a consent banner or wall is still on screen after that, the request fails with the error code cookie_wall and costs nothing, instead of returning a screenshot with the banner; pass block_cookie_banners=false to capture the page as it is.

curl -G "https://api.shotfly.dev/v1/screenshot" --data-urlencode "url=https://example.com" \
  --data-urlencode "hide_selectors=#newsletter-popup" \
  -H "Authorization: Bearer $SHOTFLY_SECRET_KEY" -o shot.png

Last updated 2026-12-01. Markdown version: /guides/screenshots-without-cookie-banners.md

Skip the browser plumbing

100 free screenshots a month. Failed captures cost nothing.

Get a free API key