Playwright reCAPTCHA in Node.js: v2, v3 and Enterprise
Solve reCAPTCHA in Playwright with Node.js: detect v2, invisible, v3 or Enterprise, capture the v3 action, inject the token and fire the callback.
Playwright reCAPTCHA handling in Node.js comes down to three jobs: work out which reCAPTCHA the page loads (v2 checkbox, invisible v2, v3 or Enterprise), get a valid token for that exact variant, and hand the token to the page the way the page expects. Clicking the checkbox from Playwright does not do it. In our own runs it opened an image grid every time. This guide shows the detection code we ran, the solve call, and the injection step for each variant. If you write Python, use our Playwright reCAPTCHA guide for Python instead.
We run CaptchaNo, so the solving step uses our API. The detection, hooks and injection code works the same whichever token source you use.
What we ran, and what we didn't
We ran four checks with Playwright 1.62.1 and headless Chromium 151 on 1 December 2026, against public demo pages only. We did not solve any captchas for this post, because no test key was available for this run. So there are no solve times or success rates here. Everything below is what the pages and Google returned.
- Detection on four pages: Google's v2 demo, Google's invisible demo, our own captcha demo page and Google's v3 score demo.
- Headless checkbox click on Google's v2 demo, three times, with a fresh browser context each run and an 8-second wait.
- Placeholder token submit: we wrote
NOT-A-REAL-TOKENinto the response field and submitted the demo form. We also sent the same string to our token verifier. - v3 action capture with an
addInitScripthook on the v3 demo.
Our detection run on 1 December 2026: four pages, three headless clicks, one captured v3 action.
Why clicking the checkbox in Playwright fails
Clicking #recaptcha-anchor only asks Google to decide whether you need a challenge, and a fresh headless browser almost always gets one. In all three of our runs the checkbox stayed aria-checked="false", the image challenge frame became visible, and the response field stayed empty.
Run 1 of 3: the click opened a "select all images with cars" grid. No token was issued.
Most of the pages ranking for this topic suggest a stealth plugin at this point. That changes some browser fingerprints, but it does not give you a token. The reliable path is to skip the widget, get the token from a solving API, and put it where the site reads it. Google documents that the checkbox's result is just a g-recaptcha-response value posted with the form, plus an optional JavaScript callback. That pair is all you need to reproduce.
Step 1: Detect which reCAPTCHA the page uses
Read the script URL and the anchor iframe, not the page's look. The script path tells you classic or Enterprise. The iframe's size parameter tells you checkbox or invisible. A render= sitekey on the script means v3. This is the function we ran:
async function detectRecaptcha(page) {
const scripts = await page.$$eval('script[src]', (s) =>
s.map((x) => x.src).filter((u) => /recaptcha\/(api|enterprise)\.js/.test(u)));
const anchors = page.frames().map((f) => f.url())
.filter((u) => /recaptcha\/(api2|enterprise)\/anchor/.test(u))
.map((u) => {
const q = new URL(u).searchParams;
return { path: new URL(u).pathname, sitekey: q.get('k'), size: q.get('size') };
});
const widgets = await page.$$eval('[data-sitekey]', (els) => els.map((e) => ({
sitekey: e.getAttribute('data-sitekey'),
callback: e.getAttribute('data-callback'),
action: e.getAttribute('data-action'),
})));
const enterprise = scripts.some((u) => u.includes('/enterprise.js'));
const v3Key = scripts.map((u) => new URL(u).searchParams.get('render'))
.find((r) => r && r !== 'explicit');
return { scripts, anchors, widgets, enterprise, v3Key };
}
On our four pages it returned what you would expect, plus two details worth knowing. Google's v2 demo declares data-callback="onSuccess", so the form is wired to a callback even though it looks like a plain checkbox. Our demo page uses render=explicit and has no data-sitekey element at all. The sitekey only appears in the anchor iframe's k parameter. Code that only reads [data-sitekey] misses explicitly rendered widgets.
| What you see | Variant | Solve type |
|---|---|---|
api.js, anchor size=normal | v2 checkbox | recaptcha_v2 |
api.js, anchor size=invisible, no render= key | Invisible v2 | recaptcha_v2 with invisible: true |
api.js?render=<sitekey> | v3 (score) | recaptcha_v3 with the page's action |
enterprise.js, checkbox or invisible widget | Enterprise checkbox (Google docs) | recaptcha_enterprise |
enterprise.js?render=<sitekey>, no widget | Score-based Enterprise | Not supported by CaptchaNo |
The v3 demo also shows an anchor with size=invisible, so check the script's render parameter before you decide it's invisible v2. If you don't want to write this yourself, the captcha detector reports the type, sitekey and action for a URL. Our reCAPTCHA Enterprise explainer covers the difference between Enterprise checkbox keys and score-based keys in more depth.
Step 2: Find the v3 action with an init script
A v3 token is tied to the action name the page passes to grecaptcha.execute, so you need that exact string. It usually sits in minified JavaScript, so it is easier to hook execute before the page loads and record what it receives. Our first attempt wrapped execute on a timer and recorded nothing, because the demo called it before the wrapper was installed. Trapping the assignment itself worked:
await context.addInitScript(() => {
window.__recaptchaCalls = [];
const hook = (obj, label) => {
let current;
Object.defineProperty(obj, 'execute', {
configurable: true,
get: () => current,
set: (fn) => {
current = typeof fn !== 'function' ? fn : function (sitekey, opts) {
window.__recaptchaCalls.push({ api: label, sitekey, action: opts && opts.action });
return fn.apply(this, arguments);
};
},
});
};
let g;
Object.defineProperty(window, 'grecaptcha', {
configurable: true,
get: () => g,
set: (value) => {
g = value;
if (value && typeof value === 'object') {
const existing = value.execute;
hook(value, 'grecaptcha');
if (existing) value.execute = existing;
}
},
});
});
// later: await page.evaluate(() => window.__recaptchaCalls)
On Google's v3 demo this returned { api: 'grecaptcha', action: 'examples/v3scores' }. As a cross-check, we listened for the request to /recaptcha/api2/reload, and its body also contained examples/v3scores. For Enterprise pages, apply the same hook to grecaptcha.enterprise. What the score means once you have it is covered in how reCAPTCHA v3 scores work.
Step 3: Request a token from the solving API
Send the page URL, the sitekey and the variant to the API, and wait for a token. This helper uses Node 18's built-in fetch. A request can return a token within the wait window, or return a task id that you poll:
async function solveRecaptcha(body) {
const headers = {
Authorization: `Bearer ${process.env.CAPTCHANO_API_KEY}`,
'Content-Type': 'application/json',
};
let res = await fetch('https://api.captchano.com/v1/solve?wait=60', {
method: 'POST', headers, body: JSON.stringify(body),
});
let task = await res.json();
while (res.status === 202 || task.status === 'solving' || task.status === 'queued') {
await new Promise((r) => setTimeout(r, 5000));
res = await fetch(`https://api.captchano.com/v1/task/${task.id}`, { headers });
task = await res.json();
}
if (task.status !== 'ready') throw new Error(`not solved: ${task.error?.code ?? res.status}`);
return task.solution.token;
}
// v2 checkbox: { type: 'recaptcha_v2', url, sitekey }
// invisible v2: { type: 'recaptcha_v2', url, sitekey, invisible: true }
// v3: { type: 'recaptcha_v3', url, sitekey, action: 'examples/v3scores' }
// Enterprise: { type: 'recaptcha_enterprise', url, sitekey }
Use the page's real URL, not the iframe URL. If the site checks that the solve and the submit come from the same network, pass a proxy and userAgent that match your Playwright context. Every field is listed on the reCAPTCHA v2 solver page and in the API docs.
Step 4: Inject the token and fire the callback
Write the token into every g-recaptcha-response textarea, then call the site's callback if it has one, because many forms only enable submit from the callback. Google's verify documentation says a token is valid for two minutes and can be verified only once. So solve right before you inject it, and solve again on every retry.
async function injectToken(page, token) {
await page.evaluate((t) => {
document.querySelectorAll('textarea[name="g-recaptcha-response"]')
.forEach((el) => { el.value = t; });
const name = document.querySelector('[data-sitekey]')?.getAttribute('data-callback');
if (name && typeof window[name] === 'function') window[name](t);
}, token);
}
const info = await detectRecaptcha(page);
const sitekey = info.widgets[0]?.sitekey ?? info.anchors[0]?.sitekey;
const token = await solveRecaptcha({ type: 'recaptcha_v2', url: page.url(), sitekey });
await injectToken(page, token);
await page.click('#recaptcha-demo-submit');
Explicitly rendered widgets pass the callback in grecaptcha.render(container, { callback }), so there is no attribute to read. Search the page source for callback: next to the render call and call that function by name. Iframes need care too. If the widget sits inside a child frame, run evaluate on that frame (Playwright's page.frames()), not the top page.
For v3, nothing reads a textarea. The page passes the token from execute straight into its own request. The cleanest swap is to make the hooked execute resolve to your solved token, or to send the site's request yourself with it. We confirmed the hook catches the call. We did not run a real v3 token through it for this post.
What a wrong token looks like
A bad token fails on the server, not in the browser, and the page doesn't say why. When we submitted NOT-A-REAL-TOKEN to Google's demo, the page came back with the widget outlined in red and "Please verify that you are not a robot." Our verifier, which calls Google's siteverify, returned {"success":false,"error-codes":["invalid-input-response"]} for the same string.
A placeholder token is rejected on the server. A real token used twice fails the same way, with timeout-or-duplicate.
The codes tell you what went wrong. invalid-input-response means the token is malformed or for a different sitekey. timeout-or-duplicate means it is older than two minutes or was already used. If a real token still gets rejected, the usual causes are the wrong variant, the wrong action, a solve for the wrong domain, or a token that expired while a slow page loaded. Our guide to rejected captcha tokens walks through each one.
Testing your own forms: use test keys instead
If the form is yours, don't solve anything in CI. Point your test environment at Google's test sitekey, which always passes and returns a token your test secret accepts. Your Playwright suite then runs the real flow without a solver or a flaky challenge. The setup, including Turnstile's test keys, is in testing reCAPTCHA and Turnstile with test keys. Solving is for third-party sites you are authorised to automate, and for end-to-end checks on production keys.
The same structure works for Cloudflare. See solving Turnstile in Playwright for Node.js, which also covers telling a challenge from a block.
How CaptchaNo handles reCAPTCHA in Playwright
CaptchaNo returns reCAPTCHA v2, invisible v2, v3 and Enterprise checkbox tokens from our own solving infrastructure, through one HTTP endpoint you can call from any Node.js script. These are the facts that matter for a Playwright suite:
- Billing: only successful solves are charged. A failed or unsolvable task costs nothing, and credit never expires.
- Scope: classic v3 keys are supported with your
actionand an optionalminScore. Score-based reCAPTCHA Enterprise keys and hCaptcha are not supported, and the detector above tells you which one you're facing before you spend anything. - Support: questions go to support@captchano.com and are answered by the engineers who run the service. There are SDKs for Node.js, Python, Go and PHP, plus a Playwright integration guide.
Rates for each type are on the pricing page. Only automate sites you own or have permission to automate.
Frequently Asked Questions
Can Playwright solve reCAPTCHA on its own?
No. Playwright can click the checkbox, but Google decides whether to issue a token. In our three headless runs on Google's demo, every click opened an image challenge and no token was issued. To finish the flow you need a token from a solving service or, on your own site, Google's test keys. Stealth plugins change the browser's fingerprint, but they do not produce a token.
How do I find the reCAPTCHA sitekey in Playwright?
Check the data-sitekey attribute first. If the widget is rendered explicitly there is no such attribute, so read the k parameter from the anchor iframe's URL through page.frames(). For v3, the sitekey is the render parameter on the api.js or enterprise.js script tag. On our demo page, only the iframe method found the key.
How long is a reCAPTCHA token valid in Playwright?
Google's verification documentation says each token is valid for two minutes and can be verified only once. This doesn't depend on Playwright: the clock starts when the token is issued. Request the token just before you inject and submit it, and get a fresh one for each retry. A reused or late token fails with the timeout-or-duplicate error.
Why does the form not submit after I inject the token?
Usually the site enables submit from a JavaScript callback, not by reading the textarea. Google's own v2 demo declares an onSuccess callback. After writing the token, call the function named in data-callback, or the callback passed to grecaptcha.render, with the token as its argument. Also check whether the widget lives inside a child frame.
Does this work for reCAPTCHA Enterprise in Playwright?
It works for Enterprise checkbox and invisible widgets, which load enterprise.js and render a visible or invisible widget. The detection and injection code is the same, and you request the recaptcha_enterprise type. Score-based Enterprise keys use a separate assessment flow. CaptchaNo does not support them, so check the script tag before you start.
Add reCAPTCHA solving to your Playwright scripts
Run the detector on your target first, then add the solve and inject steps for the variant it reports. Create a CaptchaNo account to get an API key. The full request reference is in the API docs.