Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-captcha v3 integration

I'm trying to integrate reCaptcha V3

what I tried is:

<script defer="defer"
        type="text/javascript"
        src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&amp;render=6Lda2XgUAAAAAKxRqwe9zBL09zv2ja1DYV-r">
</script>
<script type="text/javascript">
    var onloadCallback = function(){
        grecaptcha.execute('6Lda2XgUAAAAAKxRaqwev2ja1DYV-r', {action: '/foo/bar/'}).then(function(token) {
            alert(token)
        });
    };
</script>

But on loading page I get (index):1 Uncaught (in promise) null Does somebody know the reason and how could i fix it?

EDIT: I catched this error:

Uncaught TypeError: grecaptcha.execute(...).then(...).catch is not a function
    at onloadCallback ((index):18)
    at gf (recaptcha__pl.js:512)
    at Gj (recaptcha__pl.js:508)
    at recaptcha__pl.js:520
    at recaptcha__pl.js:539
onloadCallback @ (index):18
gf @ recaptcha__pl.js:512
Gj @ recaptcha__pl.js:508
(anonymous) @ recaptcha__pl.js:520
(anonymous) @ recaptcha__pl.js:539
(index):1 Uncaught (in promise) null
like image 690
minizibi Avatar asked Sep 10 '25 14:09

minizibi


1 Answers

grecaptcha.execute is created in the first script

the defer attribute will wait for page to load before executing it.

So removing the defer should make it.

Note: defer is not appearing in the official integration documentation

like image 195
user3921395 Avatar answered Sep 13 '25 02:09

user3921395