Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grecaptcha.execute() calls data-callback before user challenge

I want to invoke programmatically the invisible reCaptcha challenge. According to reCaptcha document, I have written the following code:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>reCaptcha test</title>
    <script>
        function onReCaptchaSubmit(token) {
            alert("reCaptcha challenge response:\n" + token);
        }
    </script>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    <style>
        .grecaptcha-badge {
            display: none;
        }
    </style>
</head>

<body>

<a href="javascript:void(0);" onclick="grecaptcha.execute();">Challenge</a>

<div class="g-recaptcha"
     data-sitekey="*******"
     data-callback="onReCaptchaSubmit"
     data-size="invisible">
</div>

</body>
</html>

and grecaptcha.execute(); is called from an HTML link to display reCaptcha challenge popup. In most cases, It works well. but sometimes, after calling grecaptcha.execute(); , It calls back onReCaptchaSubmit(), without displaying reCapcha popup and user challenge.

How can I fix it?
Thanks in advance.

like image 344
Askar Avatar asked Feb 06 '26 12:02

Askar


1 Answers

You expect invisible reCaptcha to show user challenge every time you call grecaptcha.execute(), but it does not work that way. In my experience, it shows challenge only when it has doubts about you. If Google is sure that you are human, it skips displaying of user challenge and proceeds to callback.

like image 102
kot9rko Avatar answered Feb 08 '26 01:02

kot9rko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!