User Agents

Web browsers and everyday web tech, explained

Detect Anti-Bot Blocking in Browser Automation

· 4 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Anti-bot systems are designed to distinguish automated browsers from real users, and they can silently block or alter your automation scripts. Detecting these blocks early saves debugging time and prevents data corruption. This guide shows you how to identify common anti-bot signals—from HTTP status codes to JavaScript traps—using browser automation tools like Selenium, Playwright, or Puppeteer.

What You'll Need

  • A browser automation tool (e.g., Playwright, Puppeteer, Selenium) installed.
  • A target website that may have anti-bot protection.
  • Basic knowledge of HTTP status codes and browser DevTools.
  • Optional: a proxy or VPN for testing different IPs (but not for bypassing blocks).

Step-by-Step

  1. Check HTTP status codes. When your script makes a request, inspect the response status. A 403 Forbidden or 429 Too Many Requests often indicates a block. Use your automation tool's response object to log status codes for every navigation and API call.
  2. Look for redirects. Anti-bot systems sometimes redirect automated traffic to a CAPTCHA page or a “verify you are human” interstitial. Monitor the final URL after navigation; if it differs from the expected URL, you're likely blocked.
  3. Inspect page content for block indicators. Search the page HTML for keywords like “captcha”, “access denied”, “robot”, “unusual traffic”, or “verify”. Use page.content() or driver.page_source and a simple regex to detect these.
  4. Analyze response headers. Headers like X-Block-Reason, X-Cache-Status, or CF-Ray (Cloudflare) can hint at a block. Log all response headers for each request and look for unusual values.
  5. Check for JavaScript challenges. Many sites run a JavaScript challenge that sets a cookie (e.g., cf_clearance for Cloudflare). If your script doesn't execute JavaScript (e.g., using a non-JS HTTP client), you'll get a block page. In a real browser, verify if the challenge cookie is set after a few seconds.
  6. Monitor network requests. Use the browser's network tab or your automation tool's request interception to see if certain resources (like analytics scripts) are blocked or if requests are being throttled.
  7. Test with a real browser profile. Run the same action manually in a regular browser. If it works, but your automation fails, the block is likely triggered by automation signatures (e.g., navigator.webdriver flag).
  8. Check for delayed responses. Anti-bot systems sometimes intentionally slow down responses to automated clients. Measure the time from request to response; a sudden increase could indicate a block.
  9. Look for hidden forms or iframes. Some blocks inject a hidden form that requires a token. Inspect the DOM for elements with display:none that contain input fields.
  10. Use headless vs. headed mode. Run your script in headed mode (with a visible browser) and compare behavior. If headed works but headless doesn't, the site is detecting headless-specific features.

Common Mistakes

  • Ignoring status codes – Always log them; a 200 doesn't mean success if the page content is a block page.
  • Not waiting for JavaScript – Some blocks appear only after a few seconds; give the page time to execute.
  • Assuming a single detection method – Anti-bot systems combine multiple signals; check all layers.
  • Using the same user agent – A default headless user agent is a red flag; but don't fake it in a way that's obviously false.
  • Not checking for cookies – Missing anti-bot cookies can cause repeated blocks.

Tips

  • Log everything: status, headers, URL, and a snippet of the page content for every request.
  • Use a unique user agent that matches a real browser version.
  • Add random delays between actions to mimic human behavior (but avoid being too predictable).
  • Use browser automation tools that allow you to override the navigator.webdriver property if needed (e.g., Playwright's addInitScript).
  • Test from different IPs to see if the block is IP-based.

Troubleshooting

If you get a 403 but the page loads in a normal browser: The site is likely detecting automation features. Try disabling the automation flag, using a real user agent, or adding a delay. If it persists, the site may be using IP reputation—try a different network.

If you see a CAPTCHA page: This is a clear block. You cannot bypass it ethically. Instead, consider using official APIs or contacting the site owner for permission.

If your script works sometimes but fails randomly: Anti-bot systems use rate limiting. Space out your requests and add random intervals.

If the page content appears but data is missing: The site may serve a partial page to bots. Compare the HTML with a manual browser's view source to spot differences.

Frequently Asked Questions

Can I detect anti-bot blocking without running a browser?

Yes, you can use HTTP clients like requests or curl to check status codes and headers, but many blocks require JavaScript execution, so a real browser is more reliable.

What is the most common anti-bot detection signal?

The navigator.webdriver property is a common flag that indicates automation. Many tools let you override it.

Is it legal to detect anti-bot blocking?

Yes, detecting blocks is legal. However, bypassing them may violate a site's terms of service. Always respect the site's rules and robots.txt.

Can I use a headless browser to avoid detection?

No, headless browsers are often more easily detected. Using headed mode with a visible window is less suspicious but still not undetectable.

Why does my script get blocked only after several requests?

This is likely rate limiting. The site allows a few requests, then blocks based on frequency. Add delays and rotate user agents if needed.

What should I do if I detect a block?

Stop the script, analyze the logs, and adjust your approach. If the block is persistent, consider using official APIs or seeking permission.