For AI agents: a documentation index is available at /llms.txt
Skip to main content

Auto-Accept Cookie Consent Banners

Automatically detect and dismiss cookie consent banners before scraping or capturing a page, so they don't block content or appear in screenshots.

Prerequisites

The simplest approach is the blockConsentModals=true query parameter. It works on BQL sessions, /screenshot, /pdf, and other REST endpoints without any selector logic:

curl -X POST \
"https://production-sfo.browserless.io/screenshot?token=YOUR_API_TOKEN_HERE&blockConsentModals=true" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}' \
--output page.png

This covers most major consent platforms (OneTrust, CookieBot, GDPR tools). For sites not handled by the built-in blocker, use the custom selector approaches below.

Steps

Use BrowserQL to load a page and automatically dismiss cookie consent banners.

View Full Code on GitHub

1. Build the BrowserQL mutation

goto with waitUntil: networkIdle ensures the page is fully settled before the if check runs. if returns null (not an error) when the selector is absent, so the mutation completes safely on pages with no banner:

https://production-sfo.browserless.io/chromium/bql?token=YOUR_API_TOKEN_HERE

2. Send the request

curl -X POST \
"https://production-sfo.browserless.io/chromium/bql?token=YOUR_API_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"query": "mutation AcceptCookies { goto(url: \"https://example.com\", waitUntil: networkIdle) { status } if(selector: \"[id*=accept], [class*=accept], button[id*=cookie]\", visible: true) { acceptBtn: click(selector: \"[id*=accept], [class*=accept], button[id*=cookie]\") { time } } screenshot { base64 } }"
}'

3. Check the output

The response includes a base64 screenshot of the page with the banner dismissed.

Next steps