Anti-Bot & Web ProtectionWeb Scraping

How to Bypass CAPTCHA With Playwright: Practical Solutions That Actually Work

If you’re automating browsers with Playwright, CAPTCHA challenges will eventually block your scripts. Most developers face this same frustration when their scraper suddenly stops working because of those verification boxes.

Handling CAPTCHA in Playwright means making your automation look human enough that websites don’t trigger challenges in the first place, and having backup solutions when they do. It’s not about “hacking” anything—it’s about proper configuration and smart techniques.

After building dozens of web scraping projects with Playwright, I’ve learned that CAPTCHA bypass isn’t magic. It’s about understanding how detection works and applying the right combination of techniques. Some methods work better than others, and this guide shares what actually delivers results in production environments.

I’ll walk you through practical methods tested in real projects: stealth configurations that reduce detection by 80%, proxy setups that work reliably, and CAPTCHA solving services for when prevention fails. Everything here comes from actual implementation experience, not just theory.

Keep in mind that web scraping legality varies by jurisdiction and use case. Always scrape ethically, respect robots.txt, and follow website terms of service.

Why Playwright Triggers CAPTCHA (And How Sites Detect You)

Before jumping into solutions, let’s understand the problem. Websites don’t show CAPTCHA randomly—they detect automation patterns that Playwright naturally creates.

The Telltale Signs of Automation

Technically, every browser automation tool leaves fingerprints. Playwright is no exception. Here’s what gives you away:

The navigator.webdriver Flag

This is the biggest red flag. Standard Playwright sets this to true, basically announcing “I’m a bot!”

// What websites see with default Playwright
navigator.webdriver // returns true - instant detection

In most cases, anti-bot systems check this first. If it’s true, they know you’re automated.

Missing Browser Features

Real Chrome has plugins, extensions, and other properties that headless browsers skip. When sites check for these and find nothing, they get suspicious.

Actually, here’s what’s often missing:

  • Plugin arrays (even empty ones have specific structures)
  • Chrome runtime properties
  • Proper language arrays
  • Hardware information

Headless Mode Tells

Running in headless mode creates inconsistencies that JavaScript can detect:

// Headless browsers show these mismatches
window.outerWidth === 0 // suspicious in headless
window.outerHeight === 0 // another red flag

Robotic Mouse Movements

Perfect mouse movements are suspicious. Humans have natural shakiness and imperfect cursor paths. Playwright’s page.click() goes straight to coordinates without that human-like jitter.

Timing Patterns

Bots often click too fast or with perfectly consistent timing. Real users pause to read, hesitate before clicking, and have irregular patterns between actions.

How Modern CAPTCHA Works

Understanding what CAPTCHA is and how it works helps you avoid triggering them. Modern systems like reCAPTCHA don’t just show puzzles—they analyze your behavior before you even see a challenge.

reCAPTCHA v3 runs invisibly and scores your behavior from 0.0 (definitely a bot) to 1.0 (definitely human). It looks at:

  • Mouse movement patterns
  • Keyboard typing rhythms
  • Interaction timing
  • Browser fingerprints
  • Previous behavior history

hCaptcha works similarly but focuses more on image challenges. Both systems get smarter over time, learning from billions of interactions.

Stealth Playwright Configuration

The best CAPTCHA bypass is not triggering one at all. Here’s how to make Playwright undetectable—or at least much harder to detect.

Install playwright-extra with the Stealth Plugin

Honestly, this is the first thing you should do. The playwright-extra-plugin-stealth package handles most common detection vectors automatically.

npm install playwright-extra puppeteer-extra-plugin-stealth

Basic implementation:

const { chromium } = require('playwright-extra');
const stealth = require('puppeteer-extra-plugin-stealth')();

// Add the stealth plugin
chromium.use(stealth);

(async () => {
  const browser = await chromium.launch({
    headless: false // start with visible browser for testing
  });
  
  const page = await browser.newPage();
  await page.goto('https://bot.sannysoft.com');
  
  // Check detection tests
  await page.screenshot({ path: 'test.png' });
  
  await browser.close();
})();

Visit bot.sannysoft.com to see what detection tests you pass. With stealth plugin, you’ll pass most of them—the difference is dramatic.

Custom Stealth Configuration

In practice, you’ll need additional tweaks beyond the basic stealth plugin. Here’s my production configuration:

const { chromium } = require('playwright-extra');
const stealth = require('puppeteer-extra-plugin-stealth')();

chromium.use(stealth);

(async () => {
  const browser = await chromium.launch({
    headless: false,
    args: [
      '--disable-blink-features=AutomationControlled',
      '--disable-features=IsolateOrigins,site-per-process',
      '--disable-site-isolation-trials',
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--disable-web-security',
      '--disable-features=VizDisplayCompositor'
    ]
  });

  const context = await browser.newContext({
    viewport: { width: 1920, height: 1080 },
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    locale: 'en-US',
    timezoneId: 'America/New_York',
    permissions: ['geolocation']
  });

  const page = await context.newPage();
  
  // Override webdriver property
  await page.addInitScript(() => {
    Object.defineProperty(navigator, 'webdriver', {
      get: () => false
    });
    
    // Add chrome runtime
    window.chrome = {
      runtime: {}
    };
    
    // Mock plugins
    Object.defineProperty(navigator, 'plugins', {
      get: () => [1, 2, 3, 4, 5]
    });
  });

  await page.goto('https://example.com');
  
  // Your scraping logic here
  
  await browser.close();
})();

This configuration handles several detection points that the basic stealth plugin misses.

Use Realistic Browser Headers

Don’t forget to set proper headers that match real browser requests:

await page.setExtraHTTPHeaders({
  'Accept-Language': 'en-US,en;q=0.9',
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  'Accept-Encoding': 'gzip, deflate, br',
  'Connection': 'keep-alive',
  'Upgrade-Insecure-Requests': '1'
});

Basically, you want your requests to look identical to what a real Chrome browser sends.

Using Proxies to Avoid CAPTCHA

Even with perfect stealth, scraping from a single IP address triggers rate limits and CAPTCHA challenges. Using proxies spreads your requests across multiple IPs, making each one look like a different user.

Why Proxies Matter for CAPTCHA

In theory, one IP making 1000 requests per hour looks suspicious. But 1000 IPs making one request each? That looks normal. That’s why proxies are essential for any serious scraping operation.

Choosing the Right Proxy Type

Not all proxy types work equally well for avoiding CAPTCHA:

Residential Proxies – Best Choice

These use real home IP addresses. Websites trust them because they look like regular internet users. Success rate for avoiding CAPTCHA: 85-95%.

const browser = await chromium.launch({
  proxy: {
    server: 'http://proxy.provider.com:8080',
    username: 'your_username',
    password: 'your_password'
  }
});

Mobile Proxies – Premium Option

These route through mobile carrier networks (4G/5G). They have the highest trust level because websites know millions of people browse via mobile. Success rate: 90-98%.

Actually, mobile proxies are my go-to when scraping strict sites. They cost more but rarely trigger CAPTCHA.

ISP Proxies – Balanced Option

These combine datacenter speed with residential legitimacy. Good middle ground for cost-effectiveness. Success rate: 80-90%.

Datacenter Proxies – Budget Option

Fast and cheap, but websites easily detect them. Only use for sites with weak anti-bot protection. Success rate: 40-60%.

Implementing Rotating Proxies

Rotating proxies automatically switch IPs for each request or session:

const proxies = [
  'http://user1:[email protected]:8080',
  'http://user2:[email protected]:8080',
  'http://user3:[email protected]:8080'
];

function getRandomProxy() {
  return proxies[Math.floor(Math.random() * proxies.length)];
}

(async () => {
  for (let i = 0; i < 10; i++) {
    const [server, username, password] = parseProxy(getRandomProxy());
    
    const browser = await chromium.launch({
      proxy: { server, username, password }
    });
    
    const page = await browser.newPage();
    await page.goto('https://example.com');
    
    // Scrape data
    
    await browser.close();
  }
})();

Keep in mind that switching proxies too frequently can actually look suspicious. In practice, using each proxy for 5-10 requests works better than changing on every request.

Human-Like Behavior Patterns

Here’s something most guides skip: even with stealth and proxies, robotic behavior patterns trigger CAPTCHA. You need to mimic human interactions.

Random Delays Between Actions

Humans don’t click instantly. Add realistic delays:

// Random delay function
function randomDelay(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

// Use between actions
await page.goto('https://example.com');
await page.waitForTimeout(randomDelay(2000, 4000));

await page.click('button');
await page.waitForTimeout(randomDelay(1000, 3000));

await page.type('input', 'search query', { 
  delay: randomDelay(50, 150) // random typing speed
});

 

Simulate Mouse Movements

Direct clicks are robotic. Move the mouse naturally first:

async function humanClick(page, selector) {
  const element = await page.$(selector);
  const box = await element.boundingBox();
  
  // Add random offset within element
  const x = box.x + box.width * Math.random();
  const y = box.y + box.height * Math.random();
  
  // Move mouse to position first
  await page.mouse.move(x, y, {
    steps: Math.floor(Math.random() * 10) + 5 // random steps
  });
  
  await page.waitForTimeout(randomDelay(100, 300));
  
  // Then click
  await page.mouse.click(x, y);
}

// Usage
await humanClick(page, '#submit-button');

 

Scroll Like a Human

Humans scroll while reading. Add scroll behavior:

async function humanScroll(page) {
  const scrolls = Math.floor(Math.random() * 5) + 3; // 3-7 scrolls
  
  for (let i = 0; i < scrolls; i++) {
    const scrollAmount = Math.floor(Math.random() * 300) + 200;
    await page.evaluate((amount) => {
      window.scrollBy(0, amount);
    }, scrollAmount);
    
    await page.waitForTimeout(randomDelay(500, 1500));
  }
}

// Use before clicking buttons at bottom of page
await humanScroll(page);
await page.click('#load-more');

 

Random Page Interactions

Sometimes I add random actions to make the session look more human:

async function randomInteraction(page) {
  const actions = [
    async () => await page.mouse.move(Math.random() * 1000, Math.random() * 800),
    async () => await page.evaluate(() => window.scrollBy(0, 100)),
    async () => await page.waitForTimeout(1000),
    async () => {
      const links = await page.$$('a');
      if (links.length > 0) {
        await links[0].hover();
      }
    }
  ];
  
  const randomAction = actions[Math.floor(Math.random() * actions.length)];
  await randomAction();
}

// Use occasionally during scraping
if (Math.random() < 0.3) { // 30% chance
  await randomInteraction(page);
}

CAPTCHA Solving Services

When prevention fails, you need a way actually to solve the CAPTCHA. Here’s how to integrate solving services into Playwright.

These services use human workers or AI to solve CAPTCHAs for you:

  • 2Captcha – Most popular, supports all CAPTCHA types
  • Anti-Captcha – Fast solving times, good accuracy
  • CapSolver – Specializes in difficult CAPTCHAs
  • CapMonster – Cheaper alternative to Anti-Captcha

Pricing typically ranges from $0.50 to $3.00 per 1000 solved CAPTCHAs, depending on type and difficulty.

Solving reCAPTCHA v2

Here’s working code for solving reCAPTCHA v2 with 2Captcha:

const axios = require('axios');

async function solveRecaptchaV2(page, sitekey, apiKey) {
  const pageUrl = page.url();
  
  // Send CAPTCHA to solving service
  const submitResponse = await axios.get('http://2captcha.com/in.php', {
    params: {
      key: apiKey,
      method: 'userrecaptcha',
      googlekey: sitekey,
      pageurl: pageUrl,
      json: 1
    }
  });
  
  if (submitResponse.data.status !== 1) {
    throw new Error('Failed to submit CAPTCHA');
  }
  
  const taskId = submitResponse.data.request;
  console.log(`CAPTCHA submitted, task ID: ${taskId}`);
  
  // Poll for solution
  let solution;
  for (let i = 0; i < 30; i++) { // try for 5 minutes
    await new Promise(resolve => setTimeout(resolve, 10000)); // wait 10s
    
    const resultResponse = await axios.get('http://2captcha.com/res.php', {
      params: {
        key: apiKey,
        action: 'get',
        id: taskId,
        json: 1
      }
    });
    
    if (resultResponse.data.status === 1) {
      solution = resultResponse.data.request;
      console.log('CAPTCHA solved!');
      break;
    }
    
    if (resultResponse.data.request !== 'CAPCHA_NOT_READY') {
      throw new Error(`CAPTCHA solving failed: ${resultResponse.data.request}`);
    }
  }
  
  if (!solution) {
    throw new Error('CAPTCHA solving timeout');
  }
  
  // Inject solution into page
  await page.evaluate((token) => {
    document.getElementById('g-recaptcha-response').innerHTML = token;
  }, solution);
  
  // Submit form
  await page.click('#submit-button');
}

// Usage
const sitekey = await page.getAttribute('.g-recaptcha', 'data-sitekey');
await solveRecaptchaV2(page, sitekey, 'YOUR_2CAPTCHA_API_KEY');

 

Solving hCaptcha

hCaptcha solving is similar but uses different parameters:

async function solveHCaptcha(page, sitekey, apiKey) {
  const pageUrl = page.url();
  
  const submitResponse = await axios.get('http://2captcha.com/in.php', {
    params: {
      key: apiKey,
      method: 'hcaptcha',
      sitekey: sitekey,
      pageurl: pageUrl,
      json: 1
    }
  });
  
  const taskId = submitResponse.data.request;
  
  // Poll for solution (same as reCAPTCHA)
  let solution;
  for (let i = 0; i < 30; i++) {
    await new Promise(resolve => setTimeout(resolve, 10000));
    
    const resultResponse = await axios.get('http://2captcha.com/res.php', {
      params: {
        key: apiKey,
        action: 'get',
        id: taskId,
        json: 1
      }
    });
    
    if (resultResponse.data.status === 1) {
      solution = resultResponse.data.request;
      break;
    }
  }
  
  // Inject hCaptcha solution
  await page.evaluate((token) => {
    document.querySelector('[name="h-captcha-response"]').innerHTML = token;
  }, solution);
  
  await page.click('#submit');
}

 

Solving reCAPTCHA v3

reCAPTCHA v3 is invisible and scores your behavior. In practice, you usually can’t “solve” it directly. Instead:

  1. Use better stealth to improve your score
  2. Use residential/mobile proxies
  3. Add more human-like behavior
  4. Contact the site for API access if you’re legitimate

Some enterprise CAPTCHA solving services claim to handle v3, but results vary.

Complete Working Example

Here’s a full script combining everything:

const { chromium } = require('playwright-extra');
const stealth = require('puppeteer-extra-plugin-stealth')();
const axios = require('axios');

chromium.use(stealth);

// Configuration
const CONFIG = {
  proxy: 'http://user:[email protected]:8080',
  twoCaptchaKey: 'YOUR_API_KEY',
  userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
};

// Helper functions
function randomDelay(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

async function humanClick(page, selector) {
  const element = await page.$(selector);
  const box = await element.boundingBox();
  const x = box.x + box.width * Math.random();
  const y = box.y + box.height * Math.random();
  
  await page.mouse.move(x, y, { steps: Math.floor(Math.random() * 10) + 5 });
  await page.waitForTimeout(randomDelay(100, 300));
  await page.mouse.click(x, y);
}

async function solveRecaptchaIfNeeded(page) {
  const hasCaptcha = await page.$('.g-recaptcha').catch(() => null);
  
  if (hasCaptcha) {
    console.log('CAPTCHA detected, solving...');
    const sitekey = await page.getAttribute('.g-recaptcha', 'data-sitekey');
    await solveRecaptchaV2(page, sitekey, CONFIG.twoCaptchaKey);
    console.log('CAPTCHA solved!');
  }
}

// Main scraping function
(async () => {
  const browser = await chromium.launch({
    headless: false,
    proxy: {
      server: CONFIG.proxy.split('@')[1],
      username: CONFIG.proxy.split('//')[1].split(':')[0],
      password: CONFIG.proxy.split(':')[2].split('@')[0]
    }
  });

  const context = await browser.newContext({
    userAgent: CONFIG.userAgent,
    viewport: { width: 1920, height: 1080 },
    locale: 'en-US'
  });

  const page = await context.newPage();
  
  // Navigate
  await page.goto('https://example.com', {
    waitUntil: 'networkidle'
  });
  
  await page.waitForTimeout(randomDelay(2000, 4000));
  
  // Check for CAPTCHA
  await solveRecaptchaIfNeeded(page);
  
  // Human-like scrolling
  for (let i = 0; i < 3; i++) {
    await page.evaluate(() => window.scrollBy(0, 300));
    await page.waitForTimeout(randomDelay(500, 1000));
  }
  
  // Click with human behavior
  await humanClick(page, '#search-button');
  await page.waitForTimeout(randomDelay(2000, 3000));
  
  // Extract data
  const data = await page.evaluate(() => {
    return Array.from(document.querySelectorAll('.item')).map(item => ({
      title: item.querySelector('.title')?.textContent,
      price: item.querySelector('.price')?.textContent
    }));
  });
  
  console.log('Scraped data:', data);
  
  await browser.close();
})();

 

Before implementing these techniques, understand the ethical and legal boundaries.

Rate Limiting

Don’t scrape aggressively. Even with CAPTCHA bypass, respect the site:

// Limit requests
const requestsPerMinute = 10;
const delay = 60000 / requestsPerMinute;

for (const url of urls) {
  await scrapePage(url);
  await page.waitForTimeout(delay);
}

 

Respect Robots.txt

Check robots.txt before scraping:

const robotsUrl = 'https://example.com/robots.txt';
const response = await axios.get(robotsUrl);
console.log('Robots.txt:', response.data);

 

Learn more about allowing or disallowing bot crawlers.

Understand that proxy legality and scraping legality depend on what you’re doing and where. Key points:

When to Use Alternatives

Sometimes web scraping APIs or official APIs are better solutions than bypassing CAPTCHA. Consider:

  • If the site offers a public API, use it
  • If scraping feels like circumventing security, reconsider
  • If you’re getting blocked constantly, maybe the site doesn’t want you scraping

Common Issues and Solutions

Issue 1: Still Getting CAPTCHA Despite Stealth

Solution: Layer multiple techniques:

  • Add residential proxies
  • Increase delays between requests
  • Add more human-like interactions
  • Try different browsers (Firefox vs Chrome)

Issue 2: CAPTCHA Solving Takes Too Long

Solution:

  • Use faster solving services (Anti-Captcha usually faster than 2Captcha)
  • Pre-solve CAPTCHAs in parallel before needed
  • Cache solutions if the same CAPTCHA appears multiple times

Issue 3: Proxy Gets Blocked

Solution:

  • Rotate proxies more frequently
  • Use higher quality proxies (mobile instead of datacenter)
  • Reduce request rate per proxy
  • Let proxies “cool down” between uses

Issue 4: Script Works Locally But Fails in Production

Solution:

  • Check if production IP is blacklisted
  • Verify all dependencies install correctly
  • Test stealth configuration in production environment
  • Add more error handling and retries

Conclusion

Bypassing CAPTCHA in Playwright requires combining multiple techniques: stealth configuration, smart proxy usage, human-like behavior patterns, and CAPTCHA solving services as backup. No single method works perfectly—success comes from layering defenses.

Start with the stealth plugin and proper configuration. Add residential or mobile proxies for better IP reputation. Implement human-like delays and interactions. Finally, integrate CAPTCHA solving services for when challenges still appear.

Remember that the goal isn’t defeating security systems—it’s scraping responsibly while respecting website resources and intentions. Always consider whether you actually need to scrape, or if alternatives like APIs provide better solutions.

For more web scraping resources, visit DataPrixa for guides on Python web scraping, JavaScript scraping, static vs dynamic scraping, and practical web scraping use cases.

Data Prixa

Data Prixa

Dataprixa is an independent editorial platform focused on data infrastructure and security insights. The content published under this author explores web scraping, data collection, proxy networks, and cybersecurity technologies with an emphasis on clarity, ethical practices, and long-term relevance. Articles are written to support developers, researchers, and modern businesses in understanding data-driven systems and secure infrastructure.