Skip to content

Instantly share code, notes, and snippets.

@shellj
Created April 22, 2020 03:26
Show Gist options
  • Save shellj/afb66de1c6316d2316b4b14c979d271c to your computer and use it in GitHub Desktop.
Save shellj/afb66de1c6316d2316b4b14c979d271c to your computer and use it in GitHub Desktop.
reCAPTCHA v3 Invalid site key or not loaded in api.js
recaptcha__zh_cn.js:534 Uncaught Error: Invalid site key or not loaded in api.js: xxxxxxx
<html>
<head>
<title>Hello</title>
</head>
<body>
<h3>hello</h3>
<button onclick='cha()'>go</button>
<script src="https://recaptcha.net/recaptcha/api.js?render=xxxxxxx"></script>
<script>
function cha() {
grecaptcha.execute('xxxxxxx', {action: 'homepage'}).then(function(token) {
console.log('token:' + token);
});
}
</script>
</body>
</html>
@IljaPHP
Copy link

IljaPHP commented May 20, 2022

Recaptcha script must be connected with public key, like:

<script src="https://www.google.com/recaptcha/api.js?render=XXXXXXXXXXXXX__PUBLIC_KEY_XXXXXXXXX"></script>

In my case, problem was: there was't key in this line, it was like:

<script src="https://www.google.com/recaptcha/api.js?render="></script>

(it was PHP error)

I think, you can get same error if you will use DIFFERENT public keys in the JS script connection and in the recaptcha execute method:

grecaptcha.execute('XXXXXXXXXXXXX__PUBLIC_KEY_XXXXXXXXX', {action: 'homepage'}).then(function (token) { var captchaElems = document.getElementsByClassName('g-recaptcha-response-v3'); for (var i = 0; i < captchaElems.length; i++) { captchaElems[i].value = token; } });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment