Skip to content
🤖

Puppeteer + CaptchaSonic

Seamless captcha solving for your Puppeteer automation and web scraping workflows.

Quick Install

npm install puppeteer captchasonic
1

Set up the solver

Import Puppeteer and initialize the CaptchaSonic client.

const puppeteer = require('puppeteer');
const CaptchaSonic = require('captchasonic');

const solver = new CaptchaSonic('YOUR_API_KEY');
2

Launch browser and navigate

Open a browser instance and go to the target page.

const browser = await puppeteer.launch({
  headless: false,
  args: ['--no-sandbox']
});
const page = await browser.newPage();
await page.goto('https://example.com/protected-page', {
  waitUntil: 'networkidle2'
});
3

Detect and solve the captcha

Identify the captcha type, extract parameters, and solve it.

// Find the captcha sitekey
const sitekey = await page.$eval(
  '.g-recaptcha', el => el.getAttribute('data-sitekey')
);

// Send to CaptchaSonic for solving
const result = await solver.solve({
  type: 'ReCaptchaV2',
  websiteURL: page.url(),
  websiteKey: sitekey,
});
4

Apply token and proceed

Inject the solution token and trigger form submission.

// Set the response
await page.evaluate((token) => {
  document.getElementById('g-recaptcha-response')
    .innerHTML = token;
  // Trigger callback if exists
  if (typeof ___grecaptcha_cfg !== 'undefined') {
    Object.values(___grecaptcha_cfg.clients)
      .forEach(c => c.callback(token));
  }
}, result.solution.token);

// Wait for navigation after captcha solve
await page.waitForNavigation({ timeout: 10000 });
console.log('Captcha solved successfully!');

Ready to automate?

Get your API key and start solving captchas in minutes. Free $0.50 bonus credits included.

Get API Key