How to Change User Agent to Solve Cloudflare

Anh Tuan
Data Science Expert
14-Jan-2025
Why User Agent Matters for passing Cloudflare
What Is a User Agent?
A User Agent (UA) is a string sent by your browser or client to identify itself to the server. It typically includes details like the browser name, version, operating system, and device type. For example:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36.
Cloudflare analyzes this string to detect bots. If your UA matches known automation tools (e.g., Python-Requests or HeadlessChrome), youโll trigger Cloudflareโs anti-bot systems.
Step-by-Step: Changing Your User Agent
1. Identify the Targetโs Expected User Agent
Before customizing, check what User Agents real users of the site are using. Tools like WhatIsMyBrowser or browser developer tools (Network tab > Headers) can help. For example, if the site is popular with Chrome users, mimic their UA.
2. Set a Custom User Agent in Your Code
Hereโs how to modify the UA in popular programming languages:
Python (Requests Library)
python
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
response = requests.get('https://example.com', headers=headers)
JavaScript (Node.js with Axios)
javascript
const axios = require('axios');
axios.get('https://example.com', {
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
});
Using Headless Browsers (Puppeteer)
javascript
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
await page.goto('https://example.com');
})();
3. Rotate User Agents
Using the same UA repeatedly can still flag you. Rotate UAs from a predefined list to mimic diverse users. Tools like Fake UserAgent simplify this:
python
from fake_useragent import UserAgent
import requests
ua = UserAgent()
headers = {'User-Agent': ua.random}
response = requests.get('https://example.com', headers=headers)
Common Mistakes to Avoid
-
Using Outdated User Agents
Cloudflare maintains lists of suspicious UAs. Avoid strings tied to old browser versions (e.g.,Chrome/58.0.3029.110from 2017). -
Ignoring Headless Browser Fingerprints
Even with a valid UA, headless browsers leak automation signals (e.g., missing plugins likenavigator.plugins). Use stealth plugins likepuppeteer-extra-plugin-stealth. -
Forgetting IP Rotation
Pair UA rotation with residential proxies to avoid IP-based blocks. Static or sticky proxies work best for maintaining session consistency. -
Combine with TLS Fingerprinting
Cloudflare checks TLS handshake patterns. Libraries likecurl_cffi(Python) ortls-client(JavaScript) mimic real browser TLS fingerprints, reducing detection risk.
Final Thoughts
Changing your User Agent is a simple yet powerful way to bypass Cloudflare, but itโs not foolproof. Combine it with IP rotation, TLS fingerprinting, and anti-detection tools for robust results.
Happy scraping! ๐ค
Compliance Disclaimer: The information provided on this blog is for informational purposes only. CapSolver is committed to compliance with all applicable laws and regulations. The use of the CapSolver network for illegal, fraudulent, or abusive activities is strictly prohibited and will be investigated. Our captcha-solving solutions enhance user experience while ensuring 100% compliance in helping solve captcha difficulties during public data crawling. We encourage responsible use of our services. For more information, please visit our Terms of Service and Privacy Policy.
More

Browser Use vs Browserbase: Which Browser Automation Tool Is Better for AI Agents?
Compare Browser Use vs Browserbase for AI agent automation. Discover features, pricing, and how to solve CAPTCHAs with CapSolver for seamless workflows.

Anh Tuan
27-Jan-2026

IP Bans in 2026: How They Work and Practical Ways to Bypass Them
Learn how to bypass ip ban in 2026 with our comprehensive guide. Discover modern IP blocking techniques and practical solutions like residential proxies and CAPTCHA solvers.

Lucas Mitchell
26-Jan-2026

How to Solve Captcha in Pydoll with CapSolver Integration
Learn how to solve reCAPTCHA and Cloudflare Turnstile in Pydoll using CapSolver for stealthy, async, CDP-based browser automation.

Lucas Mitchell
23-Jan-2026

The Best API Search Companyโs Homepage: A Powerful Guide for Smarter Data Discovery
Evaluate the best api search company's homepage with our expert guide. Learn to assess technical transparency, developer experience, and core features for smarter data discovery and reliable API integration.

Nikolai Smirnov
23-Jan-2026

Top 10 No-Code Scrapers to Use in 2026
A curated list of the best no-code web scraping tools to use in 2026. Compare AI-powered scrapers, visual point-and-click platforms, pricing, pros and cons, and real-world use cases.

Lucas Mitchell
21-Jan-2026

How to Solve Captcha in Maxun with CapSolver Integration
A practical guide to integrating CapSolver with Maxun for real-world web scraping. Learn how to handle reCAPTCHA, Cloudflare Turnstile, and CAPTCHA-protected sites using pre-auth and robot workflows.

Ethan Collins
21-Jan-2026

