HeadlinesBriefing favicon HeadlinesBriefing.com

Clean Web Screenshots Without Cookie Banners

DEV Community •
×

Automated website screenshots are frequently ruined by GDPR consent dialogs, which now cover 90% of websites. A developer building a link preview feature found existing APIs inadequate for handling these pervasive banners, prompting a custom solution using Node.js and Playwright.

The approach detects cookie banners using predictable patterns like common IDs, classes, and ARIA labels, then hides them via page.evaluate() instead of clicking. This avoids triggering tracking cookies and is faster, adding only ~200ms to the process while making 95%+ of screenshots usable for clean previews.

The solution is packaged into an Express API with concurrency control, User-Agent rotation, and resource blocking for speed. It's available as a free-tier API on RapidAPI. Future enhancements may include chat widget removal and ad blocking, addressing common visual clutter in automated web scraping and preview generation.