Back to Blog
December 10, 20251 min readMike DevTutorialPlaywrightCode
Using CaptchaSonic with Playwright: A Complete Guide
Learn how to integrate our solver directly into your Playwright automation scripts for seamless scraping.
Playwright is fantastic for modern web automation. Combined with CaptchaSonic, it becomes unstopppable.
Installation
First, install our helper library.
npm install captchasonic-solver
Basic Setup
Here is how you intercept requests and solve challenges on the fly.
import { chromium } from 'playwright';
import { SonicSolver } from 'captchasonic-solver';
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
const solver = new SonicSolver('YOUR_API_KEY');
// Navigate to target
await page.goto('https://example.com/login');
// Wait for CAPTCHA
const frame = page.frameLocator('iframe[src*="recaptcha"]');
if (await frame.isVisible()) {
const solution = await solver.solve({
websiteURL: page.url(),
websiteKey: 'SITE_KEY'
});
// Inject solution
await page.evaluate((token) => {
document.getElementById('g-recaptcha-response').innerHTML = token;
}, solution);
}
await browser.close();
})();
Best Practices
- Reuse Sessions: Don't create a new browser context for every request.
- Err on Caution: Use retry logic for network timeouts.
© 2026 CaptchaSonic. All rights reserved.