Golang Captcha Solver: reCAPTCHA and Turnstile
Solve reCAPTCHA and Turnstile in Go with chromedp: read the sitekey, get a token, inject it and fire the callback. Tested on chromedp v0.24.3.
A Golang captcha solver setup has three parts: chromedp reads the widget from the page, a solving API returns a token, and chromedp writes that token back and fires the page's callback. The Go captcha SDKs we read for this guide cover only the middle step: they return a token string and stop. This guide covers all three for reCAPTCHA v2 and Cloudflare Turnstile. Every snippet compiles against chromedp v0.24.3, the current release, and we ran each step and show the output. If you work in Node.js, the same flow is in our Puppeteer reCAPTCHA script.
What we ran, and what we didn't
All of this was run on 2026-12-04 (UTC) with Go 1.27.2, chromedp v0.24.3 (released 2026-12-03), headless Chrome 158 on macOS, and the CaptchaNo Go SDK v1.0.0.
- Reading the sitekey, callback name and user agent on Google's public reCAPTCHA demo.
- Submitting the demo form with a placeholder token, to see what a rejected token looks like.
- A local Turnstile form using Cloudflare's always-pass test sitekey, read with chromedp and checked against Cloudflare's siteverify with the published test secrets.
- A local reCAPTCHA form using Google's test key, to check whether filling the response field fires
data-callback. - The SDK's error path, using a deliberately invalid API key.
We ran no real solves, because this machine had no test API key. The browser steps, the siteverify answers and the error codes below are real. The solve call is the SDK's documented call. We compiled it but did not run it against a live key.
chromedp changed its API: older tutorials no longer compile
Since chromedp v0.17.0 (2026-10-03), Evaluate and Run are generic. Run now takes a single action and returns that action's value. Most chromedp captcha snippets online use the old style, where you pass a pointer to Evaluate and give Run a list of actions. We compiled that style against v0.24.3, and Go stopped with "too many arguments in call to chromedp.Run" and "cannot infer T". Here is the same sitekey read in both styles:
// chromedp v0.16 and earlier: no longer compiles
var sitekey string
err := chromedp.Run(ctx,
chromedp.Navigate(pageURL),
chromedp.Evaluate(`document.querySelector(".g-recaptcha").dataset.sitekey`, &sitekey),
)
// chromedp v0.17 and later
if err := chromedp.Do(ctx, chromedp.Navigate(pageURL)); err != nil {
log.Fatal(err)
}
sitekey, err := chromedp.Run(ctx,
chromedp.Evaluate[string](`document.querySelector(".g-recaptcha").dataset.sitekey`))
Two more changes matter for this flow. Multi-step sequences now go through chromedp.Do, which takes actions that return nothing. Selector options such as chromedp.ByID are gone too, so a leftover one fails to build with "undefined: chromedp.ByID". Since v0.24.0 there is also a WithRuntimeDisabled option that attaches without enabling the Runtime domain. That's worth knowing if you are tuning detection, but it isn't needed for the token flow.
Step 1: Set up the project and the browser
Install the two modules, put your API key in the environment, and start Chrome with a normal user agent. The SDK uses only the standard library and needs Go 1.21 or later. Its source and full reference are on the captchano-go repository.
go mod init example.com/scraper
go get github.com/DishantSinghDev2/captchano-go@v1.0.0
go get github.com/chromedp/chromedp@v0.24.3
export CAPTCHANO_API_KEY=cn-...
The user agent matters. In our run, chromedp's default headless Chrome reported HeadlessChrome/158.0.0.0 in navigator.userAgent. That's an easy signal for a site to flag, and you shouldn't send it to a solver either. Override it when you build the allocator:
opts := append(chromedp.DefaultExecAllocatorOptions[:],
// The default headless user agent contains "HeadlessChrome".
chromedp.UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"),
)
alloc, cancelAlloc := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancelAlloc()
ctx, cancel := chromedp.NewContext(alloc)
defer cancel()
Step 2: Detect the widget and read the sitekey
Run one script that finds a Turnstile or reCAPTCHA widget and returns its sitekey, action, cData and callback name. With the generic API you can decode the result straight into a struct pointer. A null from the page becomes a nil pointer, which means there's no captcha on the page:
// widget is what detectJS returns; a nil *widget means no captcha on the page.
type widget struct {
Type string `json:"type"`
Sitekey string `json:"sitekey"`
Action string `json:"action"`
CData string `json:"cdata"`
Callback string `json:"callback"`
}
const detectJS = `(() => {
const ts = document.querySelector('.cf-turnstile[data-sitekey]');
if (ts) return {type: 'turnstile', sitekey: ts.dataset.sitekey,
action: ts.dataset.action || '', cdata: ts.dataset.cdata || '', callback: ts.dataset.callback || ''};
const rc = document.querySelector('.g-recaptcha[data-sitekey]');
if (rc) return {type: 'recaptcha_v2', sitekey: rc.dataset.sitekey,
action: '', cdata: '', callback: rc.dataset.callback || ''};
const a = document.querySelector('iframe[src*="/recaptcha/api2/anchor"]');
if (a) return {type: 'recaptcha_v2', sitekey: new URL(a.src).searchParams.get('k'),
action: '', cdata: '', callback: ''};
return null;
})()`
func detect(ctx context.Context) (*widget, error) {
return chromedp.Run(ctx, chromedp.Evaluate[*widget](detectJS))
}
Results from our runs:
| Page | What detect returned |
|---|---|
| Google's reCAPTCHA demo | recaptcha_v2, sitekey 6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-, callback onSuccess |
| example.com | nil (no widget) |
| Local form, Turnstile test sitekey | turnstile, sitekey 1x00000000000000000000AA, action login, callback onTs |
Widgets rendered with grecaptcha.render() have no data-sitekey. The anchor-iframe fallback picks those up from the k= parameter. Our guide to finding a reCAPTCHA site key covers the other places a key can be. reCAPTCHA v3 has no widget at all. You need the action name the page passes to grecaptcha.execute, and our reCAPTCHA v3 walkthrough shows how to find it before you request a token.
Step 3: Request the token from Go
Call the SDK with the page URL, the sitekey and the browser's user agent, using a context that has its own timeout. chromedp's documentation warns against putting a timeout on the context of the first Run, because cancelling it closes the browser. So keep the solve's deadline on a separate context:
func solve(c *captchano.Client, pageURL, ua string, w *widget) (string, error) {
// Separate context: never put a timeout on the browser's own context.
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
var task *captchano.Task
var err error
switch w.Type {
case "turnstile":
task, err = c.Turnstile(ctx, captchano.TurnstileParams{
URL: pageURL, Sitekey: w.Sitekey, Action: w.Action, CData: w.CData, UserAgent: ua,
})
default:
task, err = c.RecaptchaV2(ctx, captchano.RecaptchaV2Params{
URL: pageURL, Sitekey: w.Sitekey, UserAgent: ua,
})
}
if err != nil {
return "", err
}
return task.Token(), nil
}
The SDK makes one blocking request with ?wait= and falls back to polling if the solve takes longer. For Turnstile, pass the action and cData exactly as the page sets them. If the site checks that the token comes from the same network that submits it, add Proxy with the proxy your browser uses. The request fields for each type are listed in the captcha solver API reference and on the Turnstile solver page.
Handle errors with errors.Is. We called the SDK with an invalid key. It returned in 2.2 s with captchano: invalid_api_key: The API key is missing or not valid. (HTTP 401), errors.Is(err, captchano.ErrInvalidAPIKey) was true, and errors.As gave an *APIError with status 401. With an empty key, the SDK failed before sending anything and said where to create a key. That's a useful guard for a deploy where the environment variable is missing.
Step 4: Inject the token and fire the callback
Write the token into the hidden response field, then call the widget's callback yourself. Setting the field alone did nothing in our test. On a local page with Google's test key and data-callback="onSolved", the status text stayed at "not submitted" after we filled g-recaptcha-response. It changed only when we called window.onSolved(token). Google's display docs describe data-callback as the function that receives the token after a successful response, and many forms keep the submit button disabled until it runs.
// inject writes the token into every response field and fires the widget callback.
func inject(ctx context.Context, token, callback string) error {
t, _ := json.Marshal(token)
cb, _ := json.Marshal(callback)
_, err := chromedp.Run(ctx, chromedp.Evaluate[bool](`((t, cb) => {
document.querySelectorAll('[name="g-recaptcha-response"], [name="cf-turnstile-response"]')
.forEach(el => { el.value = t; });
if (cb && typeof window[cb] === 'function') window[cb](t);
return true;
})(` + string(t) + `, ` + string(cb) + `)`))
return err
}
On our Turnstile test form, inject set the field, ran onTs, and enabled the disabled submit button. json.Marshal quotes the token and the callback name, so neither can break the script.
Step 5: Submit and confirm
Click submit and wait for an element that only appears on success. Here's the full main for Google's demo:
if err := chromedp.Do(ctx, chromedp.Navigate(pageURL)); err != nil {
log.Fatal(err)
}
w, err := detect(ctx)
if err != nil {
log.Fatal(err)
}
if w == nil {
log.Println("no captcha on the page")
return
}
ua, err := chromedp.Run(ctx, chromedp.Evaluate[string](`navigator.userAgent`))
if err != nil {
log.Fatal(err)
}
token, err := solve(captchano.New(), pageURL, ua, w) // reads CAPTCHANO_API_KEY
switch {
case errors.Is(err, captchano.ErrInvalidSitekey):
log.Fatal("sitekey rejected: re-read it from the page")
case errors.Is(err, captchano.ErrTimeout):
log.Fatal("still solving after the max wait")
case err != nil:
log.Fatal(err)
}
if err := inject(ctx, token, w.Callback); err != nil {
log.Fatal(err)
}
if err := chromedp.Do(ctx,
chromedp.Click(`#recaptcha-demo-submit`),
chromedp.WaitVisible(`.recaptcha-success`),
); err != nil {
log.Fatal(err)
}
fmt.Println("form accepted")

A wrong token doesn't throw an error in Go. The page just doesn't reach the success state. When we submitted the demo with a placeholder, Google answered "Please verify that you are not a robot." That's why the example waits on .recaptcha-success: WaitVisible blocks until that element appears, so it shows whether the site accepted the token. On your own target, wait for whatever the page shows after a successful submit.
Test the Turnstile path with Cloudflare's test keys
You can build the whole Turnstile flow without spending anything. Cloudflare's test sitekey 1x00000000000000000000AA always passes and issues the dummy token XXXX.DUMMY.TOKEN.XXXX. We served a form with it on localhost, and chromedp read the token from cf-turnstile-response about 2 seconds after load.

Then we posted that token to Turnstile's siteverify endpoint from Go:
| Secret used | siteverify answer |
|---|---|
1x0000000000000000000000000000000AA (always pass) | success: true, hostname example.com, result_with_testing_key: true |
2x0000000000000000000000000000000AA (always fail) | success: false, invalid-input-response |
| Google's reCAPTCHA test secret | success: true, hostname testkey.google.com |
The hostname tells you that a test key produced the result: Cloudflare's test secrets always return example.com, and Google's return testkey.google.com. Our test keys guide lists every pair, including the Turnstile key that forces an interactive challenge.
Why a token from Go still gets rejected
Most rejections come from timing or mismatched sessions, not from the solve itself. Check these in order:
- Too late or used twice. Google's verify documentation says a reCAPTCHA token is valid for two minutes and can be verified once. Cloudflare's server-side validation docs give a Turnstile token 300 seconds and say it's meant for one use. Inject right after the solve, and never cache tokens between goroutines.
- No callback. The field is set, but the form's JavaScript never ran (Step 4).
- Different browser or IP. The user agent or IP sent with the solve doesn't match the browser that submits. Pass the browser's own
navigator.userAgentand the same proxy. - Wrong action or cData. On Turnstile and v3, these must match what the page sends.
- It isn't a widget. A Cloudflare 403 or a full-page block isn't a captcha. A token can't fix a firewall decision. Our guide to telling a Cloudflare challenge from a block shows how to tell them apart.
The longer list, with the siteverify error code for each cause, is in why valid captcha tokens get rejected.
Running many tabs at once
Give each goroutine its own tab and solve inside that tab's flow. Calling chromedp.NewContext(ctx) on an existing browser context opens a new tab in the same browser. Each tab then runs detect, solve, inject and submit on its own. The SDK client is safe for concurrent use, so you can share one *captchano.Client. Limit how many solves run at once with a buffered channel or errgroup.SetLimit, and count solves per URL so a page that keeps rejecting tokens can't keep spending.
How CaptchaNo handles the solve
CaptchaNo solves reCAPTCHA v2 (checkbox, invisible and Enterprise checkbox widgets), standard reCAPTCHA v3, Cloudflare Turnstile, DataDome and image captchas on our own solving infrastructure. Score-based reCAPTCHA Enterprise keys and hCaptcha are not supported. The Go SDK is MIT-licensed, has no third-party dependencies, takes a context.Context on every call and has a sentinel error for every API code. Failed solves are never billed and credit never expires. Rates for each type are on the pricing page. If something in this flow breaks on your target, replies to support@captchano.com come from the engineers who run the service. CaptchaNo publishes this blog. The chromedp findings above apply whichever solver you use.
Frequently Asked Questions
Can Go solve a captcha without a solving service?
Not reliably for reCAPTCHA or Turnstile. chromedp can click a checkbox with real input events, and on a trusted browser that sometimes passes without a challenge. But image challenges and risk scoring decide the outcome, not your Go code. Plain text image captchas are different: OCR libraries can read some of them, with accuracy that depends on the noise and fonts.
Why does chromedp.Evaluate with a pointer argument fail to compile?
chromedp v0.17.0, released on 2026-10-03, made Evaluate and Run generic. Evaluate now takes only the expression and returns a typed action, and Run returns that value instead of filling a pointer. Code written for v0.16 or earlier fails with "too many arguments in call to chromedp.Run". Use Evaluate[string] or Evaluate[*YourStruct], and chromedp.Do for multi-step sequences.
How long is a reCAPTCHA or Turnstile token valid in Go?
The language doesn't change the token's lifetime. Google says a reCAPTCHA token is valid for two minutes and can be verified once, and Cloudflare gives a Turnstile token 300 seconds and treats it as single-use. In Go, that means injecting the token in the same goroutine right after the solve returns, and not caching tokens in a shared map for later requests.
Do I need a proxy for captcha solving with chromedp?
Not always. Many forms accept a token solved from a different IP, but sites that compare the solving and submitting networks reject it. If tokens fail even though the callback ran and the timing was fine, pass the same proxy your Chrome instance uses in the Proxy field. Also send the browser's own user agent, not chromedp's default headless one.
Is there a CaptchaNo Go package?
Yes. The module is github.com/DishantSinghDev2/captchano-go, and v1.0.0 is on the Go module proxy. It needs Go 1.21 or later and uses only the standard library. It has typed helpers for reCAPTCHA v2 and v3, Turnstile, DataDome and image captchas, plus raw Solve, Submit and WaitFor calls. Errors are sentinels you can check with errors.Is.
Add the solver to your Go scraper
Copy the detect, solve and inject functions into your chromedp project, then test them against the test keys before a real target. Create a CaptchaNo account to get an API key, and keep it in CAPTCHANO_API_KEY, not in your source.