Puppeteer Integration
Puppeteer + CaptchaSonic
Seamless captcha solving for your Puppeteer automation and web scraping workflows.
npm
Quick Install
npm install captchasonic puppeteer01
Set up the solver
Import Puppeteer and initialize the CaptchaSonic client.
import puppeteer from 'puppeteer';
import { CaptchaSonic } from 'captchasonic';
// Solves over a native gRPC connection (no HTTP overhead)
const client = new CaptchaSonic(process.env.CAPTCHASONIC_API_KEY);02
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'
});03
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 over gRPC
const result = await client.solveRecaptchaV2Token({
websiteURL: page.url(),
websiteKey: sitekey,
});
const token = result.solution.gRecaptchaResponse;04
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));
}
}, token);
// Wait for navigation after captcha solve
await page.waitForNavigation({ timeout: 10000 });
console.log('Captcha solved successfully!');Links
Related Resources
Ready to automate?
Get your API key and start solving captchas in minutes. Free $0.50 bonus credits included.
Get API Key