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

Integration guide

Playwright integration: token injection and route interception

Playwright gives you two clean places to hand a solved token to a site: the page itself and the network layer. This guide shows both, in Node.js and Python, with the API client you need around them.

Two ways to deliver an answer

With Playwright you can either put the token into the page, where the site's own JavaScript picks it up, or add it to the outgoing request with page.route. Injection into the page is the default because it behaves exactly like a person finishing the widget. Route interception is the precise tool for single page apps that build their own JSON request and would otherwise ignore a hidden field. Both use the same solver client: one POST to /createTask, a few polls of /getTaskResult, and a solution object.

The examples use Cloudflare Turnstile in Node.js and reCAPTCHA v2 in Python, so between them you see both solution shapes (token and gRecaptchaResponse). Turnstile is billed at $0.84 per 1,000 and reCAPTCHA v2 at $0.56, only for tasks that return an answer.

Install Playwright and the browsers

  • Node.js: version 18 or newer, which has fetch built in. Run npm i playwright and then npx playwright install chromium to download the browser build. Use an ES module project ("type": "module") so top level await works.
  • Python: pip install playwright requests, then playwright install chromium. The sync API is easiest to read; the async API has the same method names with await.
  • Your key in GATESOLVER_KEY, and a balance on the account. Browser downloads are a few hundred megabytes, so cache them in CI.

Reading parameters: DOM first, network second

The quickest source of the site key is the widget container: page.locator("[data-sitekey]").getAttribute("data-sitekey"). Locators wait automatically, so you do not need a separate wait for elements that appear late. When the page renders the widget from script and no attribute exists, read the key from the network instead. The reCAPTCHA frame loads a URL containing k= followed by the key, and a v3 page loads api.js?render= with the key in the query. Turnstile loads its frame from challenges.cloudflare.com with the key in the path. Set up the listener before goto, for example with page.waitForRequest(/recaptcha\/api2\/anchor/), then parse the URL with the standard URL class. Our pages on Turnstile parameters and telling reCAPTCHA versions apart list the exact patterns.

Node.js: solve Turnstile and inject the token

import { chromium as engine } from "playwright"; // Node.js 18+

const SOLVER_HOME = "https://gatesolver.com";
const clientKey = process.env.GATESOLVER_KEY ?? "YOUR_API_KEY";
const nap = (ms) => new Promise((done) => setTimeout(done, ms));

async function solverCall(route, extra) {
  const httpRes = await fetch(`${SOLVER_HOME}/${route}`, {
    method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ clientKey, ...extra }),
  });
  const reply = await httpRes.json();
  if (reply.errorId) throw new Error(`GateSolver ${reply.errorCode}: ${reply.errorDescription ?? "no description"}`);
  return reply;
}

export async function solveWith(task, gapMs = 3000) {
  const { taskId } = await solverCall("createTask", { task });
  const deadline = Date.now() + 125_000;
  while (Date.now() < deadline) {
    await nap(gapMs);
    const latest = await solverCall("getTaskResult", { taskId });
    if (latest.status === "ready") return latest.solution;
    if (latest.status === "failed") throw new Error("task failed, not billed");
  }
  throw new Error("answer did not arrive before the deadline");
}

const browser = await engine.launch({ headless: !process.env.SHOW_BROWSER });
const page = await (await browser.newContext()).newPage();
await page.goto("https://example.com/signin", { waitUntil: "domcontentloaded" });
const widget = page.locator(".cf-turnstile[data-sitekey]").first();
const { token } = await solveWith({
  type: "AntiTurnstileTaskProxyLess", websiteURL: page.url(),
  websiteKey: await widget.getAttribute("data-sitekey"),
});
await page.locator("input[name='cf-turnstile-response']").evaluate((el, v) => { el.value = v; }, token);
await page.getByRole("button", { name: /sign in/i }).click();
await page.waitForURL((u) => !u.pathname.endsWith("/signin"));
await browser.close();

locator.evaluate runs in the page with the element as its first argument, and it does not require the element to be visible, which matters because the response input is hidden. If the widget declares data-action or data-cdata, add metadata: { action, cdata } to the task so the token matches what the page expects.

Python: add the token with page.route

Route interception lets you rewrite a request after the page builds it and before it leaves the browser. The handler below waits for the form's POST, decodes the form body, adds g-recaptcha-response, and lets the request continue with the new body. For a JSON endpoint, parse post_data with json.loads, set the field the site uses, and pass json.dumps(...) instead.

import os, time, urllib.parse
import requests
import playwright.sync_api as pw_api

PW_SOLVER = "https://gatesolver.com"
PW_KEY = os.environ.get("GATESOLVER_KEY", "YOUR_API_KEY")
held = {}

def checkbox_token(form_url: str, sitekey: str) -> str:
    post = lambda path, extra: requests.post(PW_SOLVER + path, timeout=30,
                                             json={"clientKey": PW_KEY, **extra}).json()
    opened = post("/createTask", {"task": {"type": "ReCaptchaV2TaskProxyLess",
                                           "websiteURL": form_url, "websiteKey": sitekey}})
    if opened.get("errorId", 0):
        raise RuntimeError(opened["errorCode"])
    for _ in range(40):
        time.sleep(3)
        checked = post("/getTaskResult", {"taskId": opened["taskId"]})
        if checked.get("status") == "ready":
            return checked["solution"]["gRecaptchaResponse"]
        if checked.get("errorId") or checked.get("status") == "failed":
            raise RuntimeError(checked.get("errorCode", "failed, free of charge"))
    raise TimeoutError("checkbox token not ready")

def attach_token(route):
    if route.request.method != "POST" or "token" not in held:
        return route.continue_()
    form = urllib.parse.parse_qs(route.request.post_data or "", keep_blank_values=True)
    form["g-recaptcha-response"] = [held.pop("token")]
    route.continue_(post_data=urllib.parse.urlencode(form, doseq=True))

with pw_api.sync_playwright() as runner:
    page = runner.chromium.launch().new_page()
    page.route("**/api/contact", attach_token)
    page.goto("https://example.com/contact")
    sitekey = page.locator("[data-sitekey]").first.get_attribute("data-sitekey")
    held["token"] = checkbox_token(page.url, sitekey)
    page.fill("#message", "Monthly form check")
    page.click("form button[type=submit]")
    page.wait_for_load_state("networkidle")

One caution: some pages check grecaptcha.getResponse() before they send anything, so the request never fires while the widget looks unsolved. In that case fill the hidden textarea as well; the route handler then simply confirms the field is present in the body.

Confirming the answer landed

Before you blame the token, confirm it reached the site. Playwright makes that easy to check. Wrap the submit in page.expect_response (Python) or page.waitForResponse (Node.js) with a predicate for the form endpoint, then read the response status and body. A 200 with the expected content means the site accepted the answer; a page that renders the widget again with an error means it did not. Logging the request body during development is also useful: request.post_data shows whether the response field was present and filled.

When a run fails in CI and you cannot watch it, record a trace. context.tracing.start(screenshots=True, snapshots=True) before navigation and context.tracing.stop(path="trace.zip") at the end give you a step by step replay in the trace viewer, including network calls and the DOM at each action. Traces include request bodies, so keep them out of public artifacts when the form carries personal data.

Tokens with an action or cdata

Turnstile widgets may declare data-action and data-cdata, and reCAPTCHA v3 pages pass an action name to grecaptcha.execute. Read them the same way as the key, with getAttribute or from the page source, and send them with the task: metadata for Turnstile, pageAction for v3 at $0.70 per 1,000. A token produced for a different action is valid in form but fails the site's server side check, which looks exactly like a bad token in your logs.

Handling failures

Wrap the solve in a function that retries only what can change. A failed task or ERROR_CAPTCHA_UNSOLVABLE is free, so one more task is cheap. ERROR_SERVICE_UNAVAILABLE and ERROR_RATE_LIMIT call for a short pause. Key, balance and task data errors should fail the run at once, with the error code in the message so the log explains itself. After a refusal by the site, reload with page.reload() before the next attempt; the widget instance the first token belonged to is spent. The guide on Playwright detection explains what to change when refusals repeat.

Scaling across contexts and workers

A single Playwright browser can host many isolated contexts, each with its own cookies, which is the cheapest way to run parallel sessions. Give each context its own solve, because tokens are tied to the page that requested them. In Node.js, a pool of async workers that each own a context fits well; in Python, use the async API with asyncio.gather and a semaphore sized to your memory rather than to the API, which allows unlimited concurrent tasks within 600 requests per minute per key. Save a context's storageState after a successful login so later runs skip the form, and the widget, entirely. Playwright Test users can put the solver client in a fixture; for crawling with Scrapy as the scheduler, see Scrapy with Playwright.

Common questions

Do I need the async Playwright API for this?

No. The sync Python API and the Node.js API both work; the async Python API only helps when you run many pages concurrently in one process.

Can page.route add a token to a JSON request?

Yes. Parse route.request.post_data as JSON, set the field the site expects, and continue the route with the serialized body.

Does Playwright need to run headed for tokens to work?

No. The answer is produced by GateSolver, so headless pages accept it the same way; run headed only to watch the flow while debugging.

Which browsers does this support?

Any browser Playwright drives, since the integration only uses locators, evaluate and route, which behave the same in Chromium, Firefox and WebKit.

How do I read a site key that only appears in a network request?

Start page.waitForRequest with a pattern for the widget URL before navigating, then parse the k or render parameter from the request URL.

Keep reading