Integration guide
Puppeteer integration: reCAPTCHA v2, v3 and image CAPTCHAs
Puppeteer controls Chrome over the DevTools protocol, and GateSolver turns the CAPTCHA on the page into an answer. This guide builds one small client and uses it for three different kinds of tasks.
One client, three task shapes
The integration is a single Node.js module that creates a task and polls for its result, plus a few lines of page code per CAPTCHA type. The module does not care what kind of task it carries; only the input fields, the poll interval and the solution field change. That is why one helper can handle a reCAPTCHA v2 checkbox ($0.56 per 1,000), a reCAPTCHA v3 score token ($0.70 per 1,000) and a distorted text image ($0.28 per 1,000, usually back under 1 seconds).
Setup
Use Node.js 18 or newer so fetch is available without a package. Install with npm i puppeteer, which downloads a compatible Chrome build during installation; puppeteer-core is the alternative when you bring your own browser. Mark the project as an ES module and store the key in GATESOLVER_KEY. Puppeteer changes method names between major versions now and then, so treat the calls below as current at the time of writing and check the changelog if one is missing.
The shared client
The helper accepts the poll interval as an argument. Token tasks are polled every three seconds, image tasks every second, which matches how long each kind usually takes and keeps your request count low.
// gate-client.mjs
const GATE_ROOT = "https://gatesolver.com";
const ACCOUNT_KEY = process.env.GATESOLVER_KEY ?? "YOUR_API_KEY";
const SEND_AS_JSON = { "Content-Type": "application/json" }; // shared by every call
const RETRYABLE = new Set(["ERROR_SERVICE_UNAVAILABLE", "ERROR_RATE_LIMIT", "ERROR_CAPTCHA_UNSOLVABLE"]);
async function exchange(path, payload) {
const res = await fetch(GATE_ROOT + path, {
method: "POST",
headers: SEND_AS_JSON,
body: JSON.stringify({ clientKey: ACCOUNT_KEY, ...payload }),
signal: AbortSignal.timeout(20_000), // abort a stuck request
});
return res.json();
}
async function once(task, everyMs) {
const made = await exchange("/createTask", { task });
if (made.errorId) return { err: made.errorCode };
for (let waited = 0; waited < 125_000; waited += everyMs) {
await new Promise((ok) => setTimeout(ok, everyMs));
const got = await exchange("/getTaskResult", { taskId: made.taskId });
if (got.errorId) return { err: got.errorCode };
if (got.status === "ready") return { solution: got.solution };
if (got.status === "failed") return { err: "ERROR_CAPTCHA_UNSOLVABLE" };
}
return { err: "TIMEOUT" };
}
export async function solve(task, { everyMs = 3000, attempts = 2 } = {}) {
let last;
for (let n = 0; n < attempts; n++) {
const r = await once(task, everyMs);
if (r.solution) return r.solution;
last = r.err;
if (!RETRYABLE.has(last)) break;
await new Promise((ok) => setTimeout(ok, 2000));
}
throw new Error(`no answer: ${last}`);
}
Only three error codes are retried: the service being briefly unavailable, the per key rate limit, and an unsolvable task, all of which are free. A wrong key or a zero balance stops immediately, because a second attempt would fail the same way.
reCAPTCHA v2 and v3 on the same page object
For the v2 checkbox, read data-sitekey with page.$eval, send a ReCaptchaV2TaskProxyLess task, and write gRecaptchaResponse into the #g-recaptcha-response textarea. If the checkbox is the invisible kind, add isInvisible: true; the badge in the corner instead of a box is the giveaway.
v3 needs two values from the page: the key from the render= parameter of the script URL and the action name passed to grecaptcha.execute. The action is visible in the page source or in the network tab, and the guide on finding the page action shows where. Because v3 has no field to fill, the page asks for a token itself when you click. One tidy way to hand it ours is to replace execute for the moment of the click, so the page's own code sends the token through its normal path.
import puppeteer from "puppeteer"; // npm i puppeteer
import { solve } from "./gate-client.mjs";
const browser = await puppeteer.launch({ headless: true });
const tab = (await browser.pages())[0];
await tab.goto("https://example.com/newsletter", { waitUntil: "networkidle2" });
const v3Key = await tab.$eval('script[src*="recaptcha/api.js?render="]',
(s) => new URL(s.src).searchParams.get("render"));
const { gRecaptchaResponse } = await solve({
type: "ReCaptchaV3TaskProxyLess", websiteURL: tab.url(),
websiteKey: v3Key, pageAction: "subscribe",
});
await tab.evaluate((issued) => {
const rc = window.grecaptcha;
rc.execute = () => Promise.resolve(issued); // the page receives our token
if (rc.enterprise) rc.enterprise.execute = rc.execute;
}, gRecaptchaResponse);
await tab.type("input[type=email]", "list-test@example.com");
await Promise.all([tab.waitForNavigation(), tab.click("form button")]);
await browser.close();
Swapping execute works when the page calls it at submit time, which is the common pattern. If the page requests a token on load and stores it, solve first and set the value the page stored, or add the token to the request with setRequestInterception and request.continue({ postData }). The action string must match the site exactly; a different action yields a token the site's server scores as wrong. How v3 scores work explains why.
Image CAPTCHAs: capture the pixels already on screen
For text images, send the picture the browser is showing. Downloading the image URL again often fails, because many sites generate a new code on every request, so your download would contain a different code from the one on screen. An element screenshot avoids that.
import { solve } from "./gate-client.mjs";
export async function fillTextCaptcha(tab, imgSelector, inputSelector) {
const picture = await tab.$(imgSelector);
if (!picture) throw new Error("captcha image not on the page");
const b64 = await picture.screenshot({ encoding: "base64" });
const { text } = await solve(
{ type: "ImageToTextTask", body: b64 },
{ everyMs: 1000, attempts: 3 },
);
await tab.$eval(inputSelector, (field) => { field.value = ""; });
await tab.type(inputSelector, text);
return text;
}
The body is plain base64 with no data:image prefix, which is what the screenshot call returns. Enter the text exactly as returned if the site is case sensitive. When the site rejects it, click the refresh link next to the image to get a new picture before solving again; the failed answer was not billed if the task itself failed, but a wrong answer that the site refused was a completed task. The image to text page lists the optional module and score fields.
Telling the three cases apart
A job that visits many pages should detect which case it is facing before it spends anything. Check in a fixed order: a container with data-sitekey inside a .g-recaptcha element means the v2 checkbox (or its invisible variant); a script URL with render= followed by a key means v3; an img next to a short text input, often with a name like captcha, means a text image. One page.evaluate call can return all three checks as an object, so detection costs a single round trip to the browser. If none match, do not solve; a page without a widget may simply be an error page or a block, and our notes on Puppeteer detection cover those.
Debugging a run that does not submit
Launch with headless: false and slowMo set to a few hundred milliseconds to watch each action. Forward the page's console to your terminal with tab.on("console", (m) => console.log(m.text())), which shows errors from the site's own scripts, including the ones thrown when a callback receives an unexpected value. For request level problems, enable interception temporarily and log the body of the form POST to confirm the answer field is present and non empty.
Scaling and housekeeping
Each browser tab is a separate session, and tasks run concurrently without a limit on our side, so a pool of tabs, each solving its own CAPTCHAs, scales until memory runs out. Keep the 600 requests per minute per key in mind when you run many workers: the one second image interval uses more requests than token polling, so stagger image workers or share a small queue. Close pages you no longer need, reuse browsers rather than relaunching per job, and log the task id beside every submit so a refused answer can be traced. Fewer challenges in the first place save more money than any retry policy, so tune pacing and browser setup before tuning the solver.
Common questions
Does puppeteer-core work with this client?
Yes. The client only uses fetch, and the page code uses standard Puppeteer methods that puppeteer-core shares; you just point it at your own Chrome.
Why poll image tasks every second instead of every three?
Image answers usually come back within a few seconds, so a one second interval returns the text sooner while still using few requests.
Is replacing grecaptcha.execute safe for the page?
It only changes the function for that tab and session. Use it on pages you are allowed to automate, and prefer request interception if the page calls execute on load.
Can the screenshot approach handle a CAPTCHA drawn on a canvas?
Yes. An element screenshot captures whatever is rendered, canvas included, which is often the only way to get those pixels.
What if the v3 key is not in a script tag?
Look in the network panel for the api.js request or for reload calls that include k=; the key is the same value in each place.
Keep reading
- Web scraping with PuppeteerPuppeteer scraping beyond the basics: picking the right navigation wait, bulk extraction with $$eval, blocking heavy requests and capturing JSON.
- Solve reCAPTCHA v3 in Node.jsWrap grecaptcha.execute inside a Playwright page so the site receives a solved v3 token through its own code path.
- Image to Text solver$0.28 per 1,000 tasks, answers under 1 seconds.
- PuppeteerThe Node.js library that drives Chrome and Chromium over the DevTools Protocol, popular for scraping, screenshots and PDFs.