Google REcaptcha not showing

59.9k views Asked by At

I have the following in my <body>

<div class="g-recaptcha" data-sitekey="some-key (original is right)">

and this on my <head>

<script src="//www.google.com/recaptcha/api.js"></script>

but nothing is shown, either on firefox or chrome... Is this a known issue?

6

There are 6 answers

1
panda.o24 On

Change:

<script src="//www.google.com/recaptcha/api.js"></script>

to:

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

I don't know if that's just a typo, if it isn't, adding the https: would definitely solve your problem.

0
woolm110 On

The issue I had was that it was showing most of the time but occasionally it wouldn't and I'd have to submit the form (and trigger validation) for it to show. Adding ?render=explicit to the script tag fixed it for me.

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

https://developers.google.com/recaptcha/docs/display#explicit_render

2
Shadow Wizard Love Zelda On

Just hit this obstacle, and in my case it was due to AngularJS. It's not limited to Angular, any library which binds the elements after page load can cause the Google reCAPTCHA to not show up since the element just does not exist by the time Google's code is being executed.

To solve this, first make the render explicit and supply a function to execute when the reCAPTCHA loads:

<script src='https://www.google.com/recaptcha/api.js?onload=recaptchaOnload&render=explicit' async defer></script>

Now, add a unique ID to the container, e.g.

<div id="recaptcha" class="g-recaptcha" data-sitekey="site key here"></div>

Then in the custom function wait for the element to actually exist:

var _captchaTries = 0;
function recaptchaOnload() {
    _captchaTries++;
    if (_captchaTries > 9)
        return;
    if ($('.g-recaptcha').length > 0) {
        grecaptcha.render("recaptcha", {
            sitekey: 'site key here',
            callback: function() {
                console.log('recaptcha callback');
            }
        });
        return;
    }
    window.setTimeout(recaptchaOnload, 1000);
}

This will keep trying for 10 seconds, until it finds the element, then render the reCAPTCHA into it.

0
Andrei On

make sure that <script src="//www.google.com/recaptcha/api.js"></script> is the last thing before closing of head tag. That fixed same problem for me

0
DTM On

I just had this on a system that has stricter browser settings.
Adding *.gstatic.com to the trusted list resolved it

I also added *.google.com and *.google-analytics.com

Hope that helps someone

0
crmpicco On

Make sure you don't have any content blockers activated in your browser, for example Ad-Block Plus or uBlock origin.

Disable these, refresh the page and submit the form again.