ProductsIntegrationsResourcesDocumentationPricing
Start Now

© 2026 CapSolver. All rights reserved.

CONTACT US

Slack: lola@capsolver.com

Products

  • reCAPTCHA v2
  • reCAPTCHA v3
  • Cloudflare Turnstile
  • Cloudflare Challenge
  • AWS WAF
  • Browser Extension
  • Many more CAPTCHA types

Integrations

  • Selenium
  • Playwright
  • Puppeteer
  • n8n
  • Partners
  • View All Integrations

Resources

  • Referral System
  • Documentation
  • API Reference
  • Blog
  • FAQs
  • Glossary
  • Status

Legal

  • Terms & Conditions
  • Privacy Policy
  • Refund Policy
  • Don't Sell My Info
Blog/All/How to Change User Agent to Solve Cloudflare
Jan21, 2025

How to Change User Agent to Solve Cloudflare

Anh Tuan

Anh Tuan

Data Science Expert

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 Copy
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 Copy
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 Copy
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 Copy
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

  1. Using Outdated User Agents
    Cloudflare maintains lists of suspicious UAs. Avoid strings tied to old browser versions (e.g., Chrome/58.0.3029.110 from 2017).

  2. Ignoring Headless Browser Fingerprints
    Even with a valid UA, headless browsers leak automation signals (e.g., missing plugins like navigator.plugins). Use stealth plugins like puppeteer-extra-plugin-stealth.

  3. Forgetting IP Rotation
    Pair UA rotation with residential proxies to avoid IP-based blocks. Static or sticky proxies work best for maintaining session consistency.

  4. Combine with TLS Fingerprinting
    Cloudflare checks TLS handshake patterns. Libraries like curl_cffi (Python) or tls-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! 🤖

More

AIApr 23, 2026

What Is Agentic AI and How It Works in Automated Web Interaction

Discover what agentic AI is, how it works, and its role in automated web interaction. Learn about AI agents, CAPTCHA solving, and how CapSolver streamlines automation.

Lucas Mitchell
Lucas Mitchell
About CapsolverApr 20, 2026

The Evolution of Automation Infrastructure: How CapSolver's Strategic Upgrade Empowers Data-Driven Businesses

CapSolver evolves into a core automation layer with improved UI, integrations, and enterprise-grade data capabilities.

Contents

Lucas Mitchell
Lucas Mitchell
AIApr 22, 2026

Best AI for Solving Image Puzzles: Top Tools and Strategies for 2026

Discover the best AI for solving image puzzles. Learn how CapSolver's Vision Engine and ImageToText APIs automate complex visual challenges with high accuracy.

Ethan Collins
Ethan Collins
Web ScrapingApr 22, 2026

Rust Web Scraping Architecture for Scalable Data Extraction

Learn scalable Rust web scraping architecture with reqwest, scraper, async scraping, headless browser scraping, proxy rotation, and compliant CAPTCHA handling.

Lucas Mitchell
Lucas Mitchell