reCAPTCHA
How to find the reCAPTCHA callback function
Many forms only continue when reCAPTCHA calls their callback with the token. When you supply the token from an API, you have to make that call yourself, which starts with finding the function.
What the callback does
A reCAPTCHA callback is a function the site registers when it sets up the widget. When a visitor passes the check, the library calls it with the token as its only argument. On invisible widgets the callback usually submits the form; on checkbox widgets it often enables a disabled button or stores the token in application state for a later API call.
When your automation writes a solved token into the page, the library never learns about it, so the callback never runs. Filling the hidden g-recaptcha-response field is enough for classic forms that read the field at submit time, but single page apps and invisible widgets usually need the callback. If the button stays disabled or nothing happens after injection, this is the reason.
Check the data-callback attribute
The simplest case is a widget declared in HTML:
<button class="g-recaptcha" data-sitekey="6Lc_EXAMPLE" data-callback="sendEnquiry">Send</button>
The value is the name of a global function, so window.sendEnquiry(token) calls it. Confirm it exists with typeof window.sendEnquiry in the console. If it says undefined, the function may live under a namespace, which the next sections handle. The same applies to data-expired-callback and data-error-callback; you only need the main one.
Check the render options
Sites that render the widget from JavaScript pass the callback in the options object:
grecaptcha.render('captcha-slot', {
sitekey: '6Lc_EXAMPLE',
size: 'invisible',
callback: (t) => checkout.confirm(t),
});
Search all scripts (Ctrl+Shift+F) for grecaptcha.render or callback:. A named function or a method on a global object can be called directly. An arrow function like the one above has no name you can call, but it is still reachable through the library's own configuration, which is the reliable route for any page.
Walk the ___grecaptcha_cfg clients object
The reCAPTCHA library keeps a global object called ___grecaptcha_cfg. Its clients property holds one entry per rendered widget, numbered from 0. Somewhere inside each entry, nested under property names that are minified and change between library versions, sits the options object the site passed in, including sitekey and callback. Because the property names are not stable, the dependable approach is to search the structure for an object that has a callback key next to a sitekey.
function findRecaptchaCallbacks() {
const cfg = window.___grecaptcha_cfg;
if (!cfg || !cfg.clients) return [];
const hits = [];
const seen = new WeakSet();
const visit = (node, trail, depth) => {
if (!node || typeof node !== 'object' || seen.has(node) || depth > 6) return;
seen.add(node);
if ('sitekey' in node && 'callback' in node) {
hits.push({ trail: trail.join('.'), sitekey: node.sitekey, callback: node.callback });
return;
}
for (const prop of Object.keys(node)) {
if (node[prop] instanceof Element) continue;
visit(node[prop], trail.concat(prop), depth + 1);
}
};
for (const id of Object.keys(cfg.clients)) visit(cfg.clients[id], ['clients', id], 0);
return hits;
}
Run it in the console after the widget has rendered. Each hit shows the path where the options were found, the site key and the callback. The callback may be a function or a string; a string is the name of a global function, as with data-callback. The depth limit and the WeakSet stop the walk from following circular references and DOM nodes, which the client objects contain.
Call it with your token
const [first] = findRecaptchaCallbacks();
const fn = typeof first.callback === 'function' ? first.callback : window[first.callback];
fn(solvedToken);
In automation, run both snippets through your driver: page.evaluate in Playwright or Puppeteer, execute_script in Selenium. Pass the token as an argument rather than pasting it into the script text. Also write the token into the g-recaptcha-response textarea before calling, because some callbacks ignore their argument and read the field instead.
Picking the right widget when there are several
Pages with a login form and a signup form in the same modal, or a newsletter box in the footer, have more than one client. Use the sitekey in each hit and the element the widget is attached to. A small refinement of the walker can record the container element it skipped (the Element values) so you can match the widget to its form with closest('form'). Calling the wrong callback typically submits the wrong form or does nothing visible.
When the callback does more than submit
Read the callback source once with fn.toString(). Most just set a flag and submit, but some do extra work: copy the token into a JSON payload under another name, add a timestamp, or call a site API to exchange the token for a session value. Knowing this tells you whether you can skip the browser and post directly, or whether you should keep the browser and let the callback do its job.
Making it repeatable in automation
Once you know where the callback lives on a given site, store that knowledge rather than rediscovering it on every run. A small per site record works well: whether the site needs the callback at all, whether it is a named global or must be found through the clients walk, and which form it belongs to. Your automation then runs the cheapest path first (the named function), and falls back to the walk only when the name is missing, which also tells you the site has changed its front end and is worth a quick look.
Troubleshooting
- No ___grecaptcha_cfg. The library has not loaded, or the widget sits in a cross origin iframe. Run the code in the frame's context instead.
- Clients exist but no hit. Raise the depth limit a little; a library update may have nested the options deeper.
- The callback throws. Fill the form fields first. Many callbacks validate inputs and throw on empty values.
- Enterprise pages. The same structure exists; the walker works unchanged.
The token you pass comes from a normal reCAPTCHA task; for the invisible case add isInvisible as shown in solving invisible reCAPTCHA. Task fields are listed on the reCAPTCHA v2 page, and the Puppeteer guide shows the evaluate pattern end to end.
Common questions
Is ___grecaptcha_cfg an official API?
No. It is an internal object of the reCAPTCHA library, so its inner property names can change. Search it by shape rather than by fixed paths.
Do I still need to fill the g-recaptcha-response field?
It is a good idea. Some callbacks ignore their argument and read the field, so fill it before calling.
Why does my button stay disabled after injecting the token?
The page enables it inside the callback. Calling the callback with the token usually fixes it.
Can the callback be an anonymous function?
Yes. It has no global name then, but the walk through the clients object returns a reference you can call.
Does this work for reCAPTCHA v3?
v3 has no callback; the page awaits the promise from execute. Use the execute wrapping technique from the v3 guides instead.
Keep reading
- CAPTCHA callback functionThe function a page runs once a widget passes, and why writing the token into a field sometimes changes nothing.
- Solve invisible reCAPTCHA v2Spot the floating badge, send the task with isInvisible set, then hand the token to the page through its callback.
- PuppeteerOne Puppeteer client for three jobs: the reCAPTCHA v2 checkbox, v3 scores tied to an action, and text image CAPTCHAs.
- reCAPTCHA v2 solver$0.56 per 1,000 tasks, answers under 9 seconds.