CDP API
Scrapeless Scraping Browser extends standard CDP (Chrome DevTools Protocol) functionality, adding a series of powerful custom functions to enhance browser automation capabilities. This document primarily covers CDP functions related to CAPTCHA handling.
CAPTCHA Solver Features
Feature Overview
Scraping Browser includes advanced CAPTCHA solution features, capable of automatically handling prevalent CAPTCHA types encountered on web pages.
Supported CAPTCHA Types
- reCaptcha
- Cloudflare Turnstile
- Cloudflare 5s Challenge
- AWS WAF
Event Monitoring Mechanism
Core Events
Scraping Browser provides three core events to monitor the CAPTCHA solving process:
Event Name | Description |
---|---|
Captcha.detected | CAPTCHA detected |
Captcha.solveFinished | CAPTCHA solving completed |
Captcha.solveFailed | CAPTCHA solving failed |
Event Response Data Structure
Field | Type | Description |
---|---|---|
type | string | CAPTCHA type: recaptcha turnstile |
success | boolean | Solving result |
message | string | Status message: "NOT_DETECTED" "SOLVE_FINISHED" "SOLVE_FAILED" "INVALID" |
token? | string | Token returned on success (optional) |
Implementation Example
// Listen for CAPTCHA solving events
const client = await page.createCDPSession();
client.on('Captcha.detected', (result) => {
console.log('Captcha detected:', result);
});
await new Promise((resolve, reject) => {
client.on('Captcha.solveFinished', (result) => {
if (result.success) resolve();
});
client.on('Captcha.solveFailed', () =>
reject(new Error('Captcha solve failed'))
);
setTimeout(() =>
reject(new Error('Captcha solve timeout')),
5 * 60 * 1000
);
});
Advanced Configuration API
Scraping Browser provides a series of advanced APIs for fine-grained control over the CAPTCHA solver’s behavior. The following APIs are supported:
API Name | Description |
---|---|
Captcha.setAutoSolve | Controls automatic CAPTCHA solving behavior |
Captcha.setToken | Sets the authentication token for the CAPTCHA service |
Captcha.setConfig | Configures all CAPTCHA solver parameters |
Captcha.solve | Manually triggers the CAPTCHA solving process |
Detailed API Description
1. Captcha.setAutoSolve
Configuration interface for controlling automatic CAPTCHA solving behavior.
const client = await page.createCDPSession();
await client.send('Captcha.setAutoSolve', {
autoSolve: false,
options: [{
type: 'recaptcha', // Options: recaptcha | turnstile
disabled: false,
}]
});
2. Captcha.setToken
Sets the authentication token for the CAPTCHA solving service.
await client.send('Captcha.setToken', {
apiKey: 'your-token'
});
3. Captcha.setConfig
Configures all parameters of the CAPTCHA solver.
await client.send('Captcha.setConfig', {
config: JSON.stringify(
{
apiKey: "your-token",
autoSolve: true,
enabledForRecaptcha: true,
enabledForRecaptchaV3: true,
enabledForTurnstile: true
}
)
});
4. Captcha.solve
Manually triggers the CAPTCHA solving process.
const result = await client.send('Captcha.solve', {
detectTimeout: 10 * 1000,
options: JSON.stringify([{
type: 'rcaptcha',
disabled: true, // Disable rCaptcha solving
}])
});
console.log(result); // { type: 'recaptcha', success: true, message: 'solve_finished', token: 'xxx' }