> For the complete documentation index, see [llms.txt](https://beta-4.gitbook.io/betacaptcha-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://beta-4.gitbook.io/betacaptcha-docs/shared-documents/find-the-callback-function-of-recaptcha.md).

# Find the callback function of reCaptcha

<figure><img src="/files/GZa5AN8Unji836Fc6KBb" alt=""><figcaption><p>recaptcha callback function</p></figcaption></figure>

After obtaining the successfully recognized `gRecaptchaResponse` value through the API, if you are using simulation software, such as selenium, you need to execute a callback function to tell the webpage that we have successfully recognized, so let's learn how to find this function:

Note: In some cases, there is indeed no callback function. In this case, you can directly assign values to the g-recaptcha-response container and submit the form.

## Search by automatic search function <a href="#method-4-search-by-automatic-search-function" id="method-4-search-by-automatic-search-function"></a>

Press F12 to enter the `Console`, and enter the following auto-defined function `findRecaptchaClients()`

```javascript
function findRecaptchaClients() {
// eslint-disable-next-line camelcase
  if (typeof (___grecaptcha_cfg) !== 'undefined') {
// eslint-disable-next-line camelcase, no-undef
    return Object.entries(___grecaptcha_cfg.clients).map(([cid, client]) => {
      const data = { id: cid, version: cid >= 10000 ? 'V3' : 'V2' }
      const objects = Object.entries(client).filter(([_, value]) => value && typeof value === 'object')

      objects.forEach(([toplevelKey, toplevel]) => {
        const found = Object.entries(toplevel).find(([_, value]) => (
          value && typeof value === 'object' && 'sitekey' in value && 'size' in value
        ))

        if (typeof toplevel === 'object' && toplevel instanceof HTMLElement && toplevel['tagName'] === 'DIV') {
          data.pageurl = toplevel.baseURI
        }

        if (found) {
          const [sublevelKey, sublevel] = found

          data.sitekey = sublevel.sitekey
          const callbackKey = data.version === 'V2' ? 'callback' : 'promise-callback'
          const callback = sublevel[callbackKey]
          if (!callback) {
            data.callback = null
            data.function = null
          } else {
            data.function = callback
            const keys = [cid, toplevelKey, sublevelKey, callbackKey].map((key) => `['${key}']`).join('')
            data.callback = `___grecaptcha_cfg.clients${keys}`
          }
        }
      })
      return data
    })

  }
  return []
}

findRecaptchaClients && findRecaptchaClients()
```

Then execute this function `findRecaptchaClients()` in `console` to find the corresponding function

### Case 1: If the value of the `function` returns a string value

<figure><img src="/files/eJAx9mHCY9aEWrQTQZCz" alt=""><figcaption><p><code>funtion</code> is "verifyDemoRecaptcha"</p></figcaption></figure>

As you can see, our callback function here is `verifyDemoRecaptcha`, and then we only need to execute this function in selenium.

```python
driver.execute_script(f'verifyDemoRecaptcha("{gRecaptchaResponse}")')
```

We can test this case on the website: <https://2captcha.com/vi/demo/recaptcha-v2-callback>

### Case 2: If the value of the `function` returns a function

<figure><img src="/files/pC09NLqRQ7irWHXVZmko" alt=""><figcaption><p><code>function</code> is funtion</p></figcaption></figure>

For this kind of anonymous function, we only need to execute it according to the complete path we just found, and the effect is the same, for example:

```javascript
___grecaptcha_cfg.clients['0']['M']['M'].callback('{gRecaptchaResponse}')
```

We can test this case on the website: <https://accounts.google.com/v3/signin/>
