Cloudflare Browser Integrity Check for Automated Screenshots
In this article
Configuring the Cloudflare Browser Integrity Check (BIC) for automated screenshots involves creating a specific set of firewall rules that allow your automation tool's unique identity to bypass the JavaScript challenge. The Browser Integrity Check is designed to block requests from non-browser clients or outdated browsers by analyzing the User-Agent header and performing a silent JavaScript check. When you run automated screenshot tools—such as Puppeteer, Playwright, or Selenium—they often trigger this security layer because they exhibit bot-like behavior or use default headers that Cloudflare identifies as suspicious. By implementing a targeted WAF (Web Application Firewall) skip rule, you can ensure your screenshot engine reaches the target page without being blocked by a 403 Forbidden error or a perpetual "Checking your browser" loop.
What You'll Need
- A Cloudflare account with administrative access to the domain's dashboard.
- The specific Public IP address of the server or machine running your screenshot automation.
- A custom User-Agent string that your automation script is configured to send.
- An automation framework (e.g., Playwright, Puppeteer, or Selenium) already installed and capable of setting custom headers.
Step-by-Step
-
Identify Your Automation Identity: Before changing settings in Cloudflare, you must define how your bot identifies itself. In your automation code, set a unique User-Agent string. Do not use the default "HeadlessChrome" string, as this is a primary trigger for the Browser Integrity Check. Create a specific string, such as
MyScreenshotBot/1.0 (Automation). Record this exact string and the static IP address of your screenshot server. - Access the WAF Custom Rules: Log into your Cloudflare dashboard. Select the website you are configuring. In the left-hand sidebar, navigate to Security and then select WAF (Web Application Firewall). Click on the Custom rules tab.
- Create a New Rule: Click the Create rule button. Give your rule a descriptive name, such as "Allow Screenshot Bot Bypass," so other administrators understand why this security exception exists.
-
Define the Matching Criteria: You need to create a logic gate that only allows your specific bot. Use the "And" operator to combine multiple conditions for maximum security.
- Set the first field to IP Source Address, select equals, and enter your server's public IP.
- Click And.
- Set the second field to User Agent, select equals, and enter the custom User-Agent string you defined in Step 1.
- Configure the Action: Under the "Then..." section, you must choose the correct action to bypass the integrity check. Select Skip from the dropdown menu. In the "WAF components to skip" section, check the box for Browser Integrity Check. You may also choose to skip "All remaining custom rules" if you have other security layers that might interfere with the screenshot process.
- Deploy and Test: Click Deploy to activate the rule. Now, run your automation script. Ensure the script is sending the exact User-Agent and originating from the IP you specified. If configured correctly, the bot should land directly on the page without encountering the Cloudflare challenge page.
- Verify Screenshot Quality: Once the bypass is working, verify that the screenshots are rendering correctly. Sometimes, bypassing the BIC can lead to issues with CSS or JavaScript if the site has secondary security checks. Ensure the page is fully loaded using a "networkidle" or "domcontentloaded" event before triggering the screenshot command.
Common Mistakes
One of the most frequent errors is using a generic User-Agent. Many developers try to mimic a real Chrome browser by copying a current Chrome string. While this seems logical, Cloudflare's Browser Integrity Check does not just look at the string; it looks for a match between the string and the actual browser behavior. If you claim to be Chrome 120 but fail to execute the specific TLS handshake or JavaScript challenges associated with that version, Cloudflare will flag the request as a spoof. The solution is to use a unique, non-spoofed string and explicitly allow that string in the WAF.
Another common mistake is applying the "Skip" rule to the entire world. Some users simply turn off the Browser Integrity Check globally in the Security settings. This is a critical security risk, as it opens the site to basic scrapers and DDoS tools that the BIC would otherwise block. Always use Custom Rules to limit the bypass to a specific IP and User-Agent combination.
Finally, developers often forget to handle the "Headless" flag. Even with a WAF bypass, some websites use internal scripts to detect navigator.webdriver = true. While this is not part of the Cloudflare BIC, it often happens simultaneously. Ensure your automation tool is configured to hide the webdriver property to avoid being blocked by the application layer after passing the network layer.
Tips
To improve the reliability of your screenshots, implement a retry mechanism with exponential backoff. Even with a bypass rule, occasional network timeouts or Cloudflare maintenance windows can cause a request to fail. Instead of letting the script crash, program it to wait 2, 4, and then 8 seconds before giving up.
For those operating in dynamic IP environments (like AWS Lambda or Google Cloud Functions), a static IP is difficult to maintain. In these cases, instead of filtering by IP, you can use a custom Header. Add a secret header to your request, such as X-Screenshot-Auth: your-secret-key, and configure the Cloudflare WAF rule to skip the BIC if that specific header is present. This is more flexible than IP filtering while remaining secure.
Always monitor your WAF events. Cloudflare provides a detailed log of which rules are being triggered. If your screenshots start failing, check the Security > Events log. Look for blocked requests originating from your server IP; the log will tell you exactly which rule (e.g., "Bot Fight Mode" or "Browser Integrity Check") caused the block, allowing you to adjust your skip rules accordingly.
Troubleshooting
If you are still seeing the "Checking your browser" page despite the skip rule, first verify the User-Agent. A single missing space or a capitalization difference between your code and the WAF rule will cause the match to fail. Use a tool like curl -v or a simple request logger to see exactly what the server is sending to Cloudflare.
If the User-Agent and IP are correct, check if Bot Fight Mode is enabled. Bot Fight Mode is a separate, more aggressive system than the Browser Integrity Check. If Bot Fight Mode is active, it may override your custom skip rules. You may need to upgrade to a Pro or Business plan to create more granular "Bot Management" rules, or temporarily disable Bot Fight Mode to see if it is the source of the interference.
Check for cached 403 responses. Sometimes, after a bot has been flagged, Cloudflare or the origin server may cache the block for a short period. Clear your browser cache or change the request URL slightly (e.g., add a random query string like ?t=12345) to ensure you are testing a fresh request rather than a cached block.
Ensure that your automation tool is not triggering a "JS Challenge" (the interactive checkbox). The Browser Integrity Check is a silent check. If you see a checkbox, you are likely hitting a "Managed Challenge." This happens if the site's security level is set to "High" or if the visitor's IP has a poor reputation. Lower the security level for the specific path you are screenshotting using Page Rules.
Frequently Asked Questions
Does skipping the BIC make my site vulnerable?
Only if the rule is too broad. If you limit the bypass to a single static IP and a secret User-Agent, the risk is negligible. However, disabling it globally removes a primary layer of defense against simple bots.
Can I use this with a free Cloudflare account?
Yes, Custom WAF rules are available on the free plan, though there is a limit to the number of rules you can create. The Browser Integrity Check itself is a standard feature of the free tier.
Why is my screenshot showing a blank page?
This usually happens because the screenshot is taken before the JavaScript has finished rendering the content. Use a "wait for selector" command in your code to ensure the main content is visible before capturing the image.
Will this work for all pages on my site?
Yes, if you configure the rule to apply to the entire hostname. If you only want it to work for specific pages, you can add a URI Path condition to your WAF rule.
What is the difference between BIC and Bot Fight Mode?
BIC is a basic check for browser headers and JS execution. Bot Fight Mode uses behavioral analysis and machine learning to identify bots based on how they interact with the page over time.
Do I need to change my DNS settings for this?
No, this is a configuration change within the Cloudflare WAF and does not require any changes to your DNS records or nameservers.