NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

CAPTCHA solving

How do I add CAPTCHA solving to Playwright or Puppeteer?

Both libraries share the same three moves: read the widget parameters from the page, solve them with an HTTP call from your Node.js code, and put the answer back into the page or the cookie jar.

The answer

The solving itself does not happen in the browser. Your script reads what the solver needs from the page (URL, site key, sometimes an action or extra data), sends a task to the GateSolver API from Node.js, polls until the answer is ready, and then applies it: a token goes into the page through page.evaluate, and a clearance cookie goes into the browser context. Because Playwright and Puppeteer both expose page.evaluate and cookie setters, one helper serves both.

A shared solving helper

This function uses the built in fetch of current Node.js releases, so there is nothing to install:

const GS_BASE = "https://gatesolver.com";
const GS_KEY = process.env.GATESOLVER_KEY ?? "YOUR_API_KEY";

async function gsCall(method, payload) {
  const body = JSON.stringify({ clientKey: GS_KEY, ...payload });
  const init = { method: "POST", body, headers: { "Content-Type": "application/json", Accept: "application/json" } };
  const reply = await fetch(`${GS_BASE}/${method}`, init);
  return reply.json();
}

export async function solveTask(task, everyMs = 3000) {
  const nap = (ms) => new Promise((wake) => setTimeout(wake, ms));
  const made = await gsCall("createTask", { task });
  const refused = made.errorId ? made.errorCode : null;
  if (refused) throw new Error("createTask refused: " + refused);
  const giveUpAt = performance.now() + 125_000;
  while (performance.now() < giveUpAt) {
    await nap(everyMs);
    const state = await gsCall("getTaskResult", { taskId: made.taskId });
    const pollProblem = state.errorId ? state.errorCode : null;
    if (pollProblem) throw new Error("getTaskResult refused: " + pollProblem);
    if (state.status === "ready") return state.solution;
    if (state.status === "failed") return null;
  }
  return null;
}

Use a three second interval for token tasks and one second for image tasks. A task that has not finished after 120 seconds is closed as failed and not charged.

Reading parameters from the page

Read values from the live DOM rather than hard-coding them. For reCAPTCHA v2 and Turnstile, the site key usually sits in a data-sitekey attribute:

const widgetInfo = await page.evaluate(() => {
  const box = document.querySelector(".g-recaptcha[data-sitekey], .cf-turnstile[data-sitekey]");
  if (!box) return null;
  return {
    kind: box.classList.contains("cf-turnstile") ? "turnstile" : "recaptcha",
    sitekey: box.getAttribute("data-sitekey"),
    callback: box.getAttribute("data-callback"),
  };
});

For reCAPTCHA v3 the key is in the script URL (render=) and the action is in the call to grecaptcha.execute; see finding the v3 action name.

Applying the answer

For a reCAPTCHA token, write it into g-recaptcha-response and call the site's callback when one is declared. For Turnstile, the field is cf-turnstile-response. The call is identical in both libraries:

await page.evaluate(({ answer, cb, fieldName }) => {
  document.querySelectorAll(`[name="${fieldName}"]`).forEach((el) => { el.value = answer; });
  if (cb && typeof window[cb] === "function") window[cb](answer);
}, { answer: sol.gRecaptchaResponse ?? sol.token, cb: widgetInfo.callback,
     fieldName: widgetInfo.kind === "turnstile" ? "cf-turnstile-response" : "g-recaptcha-response" });

For cookie answers such as AWS WAF, set the cookie and reload. Playwright uses context.addCookies([...]); Puppeteer uses page.setCookie(...) (or the browser level method in newer versions). The cookie name is aws-waf-token for AWS WAF and cf_clearance for a Cloudflare Challenge task, which also needs your proxy so the cookie matches your IP.

Detecting a challenge before it costs you a timeout

The helper is only useful if your script knows when to call it. After each navigation, check for the widgets you expect before waiting on your content. A short probe for a reCAPTCHA iframe, a Turnstile container, an AWS WAF CAPTCHA script or a DataDome frame tells you which task type to create, and it saves the full selector timeout you would otherwise spend waiting for content that will never appear. Keep the probe in one function and return a small description of what it found (type, site key, callback), so the rest of the code can branch on it cleanly.

Once the answer is applied, confirm that it worked. Wait for the navigation or response that follows the submit, then look for the challenge again. If it is still there, log the parameters you used and the task id, and retry once with freshly read values. Repeated failures with correct parameters usually point at something other than the token, such as an IP the site distrusts; the page on what affects token acceptance covers those cases.

Keeping solves out of the hot path

Pages that are not protected should not pay for the probe in time or money. Run it only after navigation to pages that are known to carry a widget, or when your content selector does not appear within a short first wait. Count how often each target needs a solve; that number tells you whether better pacing or a different proxy tier would be cheaper than solving.

Where the two libraries differ

  • Frames. Playwright offers page.frameLocator(); Puppeteer uses page.frames(). You rarely need to enter the widget frame, since parameters live on the host page.
  • Cookies. Playwright works at context level; Puppeteer historically at page level.
  • Waiting. Playwright locators wait automatically; in Puppeteer, wait for the result of the submit explicitly.

Full walkthroughs live in the Playwright integration and the Puppeteer integration.

Common mistakes

  • Solving before the form is filled, so the token ages while the script types.
  • Injecting into the field but never calling the callback on sites that submit through it.
  • Using the solution's user agent nowhere; for sites that check it, launch the browser with that user agent or a matching one.
  • Treating null from the helper as fatal. A failed task is free; reload the page and try again with fresh parameters.

Common questions

Do I need a plugin to solve CAPTCHAs in Playwright?

No. A small helper that calls the HTTP API from Node.js is enough; the browser only reads parameters and receives the answer.

Does the same code work in Puppeteer and Playwright?

Mostly. Both have page.evaluate; only cookie and frame methods differ slightly.

Where do I get the site key?

From the data-sitekey attribute on the widget, or from the render parameter of the reCAPTCHA v3 script URL.

What if the page has no callback?

Filling the response field and submitting the form is usually enough. If nothing happens, look for a callback registered in code.

How often should my helper poll?

Every three seconds for token tasks and every second for image tasks, giving up after about two minutes.

Keep reading