How to detect bot challenge pages in screenshots
By the Shotfly team · Published 2026-12-01
Check the response before you save the image: a cf-mitigated: challenge header, a title such as "Just a moment...", or a captcha frame on an otherwise empty page means the site served a bot check. The browser reports success either way, so a pipeline that only checks for a PNG stores the challenge as the page. This guide covers detection, not getting past the check.
Signals worth checking
| Signal | Evidence | Why |
|---|---|---|
cf-mitigated: challenge header | Strong | Cloudflare sets it on every challenge page it serves (Cloudflare docs, read 2026-12-01). |
| A title such as "Just a moment...", "Attention Required!", "Security Checkpoint", "Access Denied" or "Robot or human?" | Strong | Titles of common challenge and block pages. Keep the patterns specific, and anchor short generic ones to the start of the title, so an article about bot checks doesn't count. |
| A captcha frame: Turnstile, hCaptcha, reCAPTCHA or DataDome | Weak on its own | Login and contact forms embed the same frames. Count it only when the page has little else. |
| Status 403, 429 or 503 | Weak on its own | Real errors and rate limits use the same codes. Count it only when the page is almost empty. |
Check before you save
This function takes the page and the response from page.goto(). Playwright and Puppeteer share the status(), headers(), title() and evaluate() calls it uses, so one version serves both. Save it as detect-challenge.js:
// Works with a Playwright or a Puppeteer page and the response page.goto() returned.
const TITLES = [/^just a moment/i, /^attention required/i, /security checkpoint/i, /^access denied/i, /robot or human/i]
const CAPTCHA_FRAMES = ['challenges.cloudflare.com', 'hcaptcha.com', 'google.com/recaptcha', 'captcha-delivery.com']
/** Why this looks like a bot challenge rather than the page, or null. */
export async function challengeReason(page, response) {
if (!response) return 'no response'
const status = response.status()
if (response.headers()['cf-mitigated'] === 'challenge') return 'cf-mitigated: challenge header'
const title = await page.title()
if (TITLES.some((re) => re.test(title))) return `title "${title}"`
const { text, frames } = await page.evaluate(() => ({
text: document.body?.innerText.trim() ?? '',
frames: [...document.querySelectorAll('iframe')].map((f) => f.src),
}))
// A captcha frame alone is weak evidence: login and contact forms embed them too.
const captcha = frames.find((src) => CAPTCHA_FRAMES.some((host) => src.includes(host)))
if (captcha && text.length < 500) return `captcha on a near-empty page (${new URL(captcha).host})`
if ([403, 429, 503].includes(status) && text.length < 300) return `HTTP ${status} with almost no content`
return null
}import { chromium } from 'playwright'
import { challengeReason } from './detect-challenge.js'
const url = process.argv[2]
const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } })
const response = await page.goto(url, { waitUntil: 'load' })
const reason = await challengeReason(page, response)
if (reason) {
console.error(`Not saved: ${reason}`)
process.exitCode = 1
} else {
await page.screenshot({ path: 'screenshot.png' })
}
await browser.close()Check ordinary HTTP errors such as 404 and 500 separately, so your logs tell a missing page from a blocked one.
When you hit one
- Record the failure and the reason instead of storing the image, so you can see which sites block you.
- Retry later and more slowly; some bot protection reacts to the request rate.
- Some challenges clear themselves after a few seconds and load the real page. If you wait, cap the wait and run the check again on the page you end up with; interactive challenges don't clear on their own.
- If the site is yours, allow your capture traffic in its bot protection settings.
With Shotfly
Shotfly checks every capture for challenge and block pages before it charges. When a site serves one, the request fails with HTTP 422 and the error code target_blocked, and costs nothing. With escalation=auto, Shotfly may retry on its premium anti-bot tier, which costs 5 credits when it succeeds; max_credits caps what a request may spend. Some sites block automated browsers whatever you do, so handle target_blocked as a normal outcome.
curl -G "https://api.shotfly.dev/v1/screenshot" --data-urlencode "url=https://example.com" \
-d escalation=auto -d max_credits=5 \
-H "Authorization: Bearer $SHOTFLY_SECRET_KEY" -o shot.pngRelated
Last updated 2026-12-01. Markdown version: /guides/detect-bot-challenge-pages.md