Search tldr

How to hide cookie banners when taking a screenshot with Puppeteer

Clean Puppeteer screenshots by accepting, hiding, or blocking cookie-consent overlays. The most practical self-managed approach combines CMP auto-consent with EasyList-style blocking rules, while site-specific logic remains necessary for edge cases.

Share

How to hide cookie banners when taking a screenshot with Puppeteer

Author: Dmytro Krasun | Published: Unknown | Generated: 2025-05-15 | Domain: screenshotone.com
Tags: ‘#puppeteer’ ‘#web-scraping’ ‘#browser-automation’ ‘#cookie-consent’ ‘#screenshots’


TLDR

Cookie banners can spoil automated screenshots and may affect page behavior if simply hidden rather than accepted. The article evaluates per-site selectors, generic button-text matching, filter-list blocking, CMP auto-consent, browser extensions, and AI-assisted removal. Its recommended DIY strategy combines DuckDuckGo AutoConsent with Fanboy Cookie Monster/EasyList-style rules, supplemented by custom site handling for uncovered cases.

Key Takeaways

  • Site-specific handling is most reliable: For a known site such as Stack Overflow, Puppeteer can either inject CSS to hide .js-consent-banner or click .js-accept-cookies; accepting cookies is preferred because some sites may restrict functionality otherwise.
  • Generic text matching has fragile edge cases: Searching links and buttons for labels such as “Accept,” “Allow all,” or “OK” can work across sites including Cookiebot, Hetzner, London Stock Exchange, and DigitalOcean, but can click unintended controls, require post-click waits for animations, and needs localization support such as German Akzeptieren.
  • Blocking lists remove some overlays: @cliqz/adblocker-puppeteer can load Fanboy’s Cookie Monster list and block many cookie banners, but it does not reliably handle CMP-driven dialogs such as Cookiebot.
  • AutoConsent targets major CMPs: @duckduckgo/autoconsent attaches to a Puppeteer page after load, detects supported consent-management platforms, and can automatically opt in or opt out.
  • Use layered defenses: Combining rule-list blocking with AutoConsent provides the strongest non-extension approach, though it is not bulletproof and still requires customizations for unsupported sites.

Images & Media

Keep reading