# grecaptcha.execute is not a function: two libraries race

> grecaptcha.execute is not a function when the library is not ready, or when Enterprise owns window.grecaptcha. Google's own v3 demo loads both scripts.

Source: https://mosaicbrowser.com/blog/grecaptcha-execute-not-a-function

## Google's reCAPTCHA demo loads two libraries that race

grecaptcha.execute is not a function when the library is not ready, or when Enterprise owns window.grecaptcha. Google's own v3 demo loads both scripts.

![1 in 3: Two libraries, one global, beside a screenshot: a Mosaic leak test: every surface a site reads, checked from inside the profile page](https://mosaicbrowser.com/covers/grecaptcha-execute-not-a-function.webp)

`TypeError: grecaptcha.execute is not a function` means the object sitting on `window.grecaptcha` has no `execute` when your code asks for it. There are two usual reasons. The library has not finished loading, or the object on the page belongs to reCAPTCHA Enterprise, which keeps `execute` one level down under `grecaptcha.enterprise`. We hit the second one on Google's own reCAPTCHA v3 demo, about one load in three.

## Where we met the error

Our detection suite runs 49 public test pages against a Mosaic profile and reads each verdict. One row is Google's reCAPTCHA v3 demo at `recaptcha-demo.appspot.com`, because it is one of very few pages that print the numeric v3 score instead of hiding it. The row was failing intermittently: no score on the page, while a stock browser measured in the same session got its score every time. Four runs of one profile came back `pass, pass, unread, unread`. The stock browser went `pass, pass, pass`.

That pattern looks exactly like a finding about the profile. It was not one. With an error listener installed at document start, the failing loads all threw the same thing, inside Google's code: `TypeError: grecaptcha.execute is not a function`.

## Two scripts, one global

The demo page loads two libraries. One is `api.js?render=…`, the ordinary v3 library. The other is `enterprise.js?render=…`, the Enterprise one. Both define `window.grecaptcha`, and they do not agree on its shape. In v3, `execute` and `ready` sit on `grecaptcha` itself. In Enterprise they sit on `grecaptcha.enterprise`.

So the order the two arrive in decides what the page's own call finds. The resource timings from one passing load and one failing load:

```
pass    api.js 180ms   enterprise.js 421ms
fail    api.js 156ms   enterprise.js  97ms   TypeError: grecaptcha.execute
                                             is not a function

```

On the failing load Enterprise was on the page first, the demo called `grecaptcha.execute(…)` on an object that keeps it elsewhere, and no token was ever requested. The stock browser happened to win it on every load we measured, but the race says nothing about the profile. It is two of Google's own scripts on Google's own demo.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: REST API](https://mosaicbrowser.com/features/rest-api)

## The check that could never fail

Our first fix was a probe that asked the page whether `grecaptcha.execute` was a function. On four failing loads it said yes, every time. By the time the suite reads the page, the other library has landed and replaced the object, and the key list on `window.grecaptcha` is identical to a healthy page's. The library that lost finished loading a moment after the throw, so nothing left on the page shows the failure.

A check that cannot fail is not a check, and that one would have sat in the suite reading like one. What does differ is the demo's own status log, which narrates each step. Both outcomes print `grecaptcha.ready() fired, calling` and then `grecaptcha.execute('…', {action: 'examples/v3scores'})`. Only a passing load goes on to print `Received token from reCAPTCHA service`. The `Try again` link is no use: it is rendered on the passing page too.

So the row now reads the log. When it stops at the `execute` line, the suite reports it as unread and says the page's own library broke before asking for a token, which sends nobody off to investigate the profile's reputation. The row also polls for the score instead of sleeping a fixed time, because a fixed sleep, already raised from 20 seconds to 35, kept recording slow loads as pages that rendered nothing.

## Fixing grecaptcha.execute is not a function on your own site

If the error is in your code rather than in a demo, the cause is usually one of these:

1. The call runs before the library is ready. Wrap it: `grecaptcha.ready(() => grecaptcha.execute(siteKey, { action: 'submit' }))`. With a script loaded `async` or injected late, a bare `execute` at page load works on a fast connection and fails on a slow one.
2. The page loads `enterprise.js`. Enterprise keys and the Enterprise script use `grecaptcha.enterprise.ready` and `grecaptcha.enterprise.execute`. The v3 names are not there.
3. The page loads both. A tag manager, a plugin and a theme can each add their own copy. The order they arrive in decides which shape `window.grecaptcha` has when your callback runs, so the error comes and goes with the network. Search the page for every `recaptcha/api.js` and `recaptcha/enterprise.js` and keep one.
4. The script URL has no `render=` site key. v3's `execute(siteKey, …)` needs the library loaded with `?render=<your site key>`. Loaded with `render=explicit`, `execute` belongs to the invisible v2 widget and takes a widget id.

When you test the fix, test it twice, on a throttled connection. A race that wins on the first try is the reason this bug ships.

## What we took from it

The cheapest check was to run an untouched browser beside the profile, and it was right there in the tool. The rule we keep relearning is that a stock browser goes in the same run, at both ends, before a verdict counts as a fact about our engine. [The control that settles "is it our changes to Chromium?"](https://mosaicbrowser.com/blog/the-control-is-googles-build) is the same lesson with four lost days attached, and [Pixelscan's false positives on a stock Chrome](https://mosaicbrowser.com/blog/pixelscan-masks-stock-chrome) is it again with numbers. The full list of pages the suite reads, and what each verdict means, is in [our 49 detectors](https://mosaicbrowser.com/blog/forty-nine-detectors).

## Questions

### What does grecaptcha.execute is not a function mean?

The object on window.grecaptcha has no execute method at the moment your code calls it. Either the library has not finished loading, or the object belongs to reCAPTCHA Enterprise, which keeps execute under grecaptcha.enterprise.

### How do I fix grecaptcha.execute is not a function with reCAPTCHA Enterprise?

Call grecaptcha.enterprise.ready and grecaptcha.enterprise.execute instead of the v3 names. If the page loads enterprise.js, the v3 calls are the wrong ones even when the site key is right.

### Can I load api.js and enterprise.js on the same page?

You can, but both scripts write window.grecaptcha, so the object your code finds depends on the order they arrive in. Load the one your keys belong to and nothing else.

### Why does the error only happen sometimes?

Because the cause is timing. A script that is not ready yet, or two scripts that finish in a different order on each load, give an error that comes and goes with the network. That is also why it survives testing on a fast connection.

## Related

[49 browser fingerprint detectors, and how we read them](https://mosaicbrowser.com/blog/forty-nine-detectors): Our browser fingerprint detectors list: 49 public test pages in five groups, 40 read by a script and 9 kept as reference because they print no verdict.

[The control that settles "is it our changes?"](https://mosaicbrowser.com/blog/the-control-is-googles-build): An unchanged Chrome for Testing got the same IPHey verdict as our engine, so our changes were not the cause. Its voice list still differs from Chrome's.

[Pixelscan calls a stock Chrome masked 3 times in 20](https://mosaicbrowser.com/blog/pixelscan-masks-stock-chrome): A Pixelscan false positive, measured: an untouched Google Chrome read 'Masking detected' on 3 of 20 runs. Our fresh profiles read it once in 74.

[A retired bot test can still answer 200 and look like a pass](https://mosaicbrowser.com/blog/dead-detector-returns-200): Antoine Vastel's fp-scanner demo now serves his homepage with HTTP 200, which a challenge reader scores as a pass. His tests moved; here is where.









[setUserAgentOverride without metadata wipes your client hints](https://mosaicbrowser.com/blog/setuseragentoverride-clears-hints): Without userAgentMetadata, setUserAgentOverride left our page with empty brands while a worker reported both. We set the User-Agent at launch instead.

[Why navigator.webdriver is true, and why false proves little](https://mosaicbrowser.com/blog/why-navigator-webdriver-true): navigator.webdriver is the W3C WebDriver flag, true under Selenium, Playwright, Puppeteer or headless Chrome. A Chrome reading true scored 100 on IPHey.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
