Google REcaptcha not showing
Just hit this obstacle, and in my case it was related to AngularJS. It is not limited to Angular, any library that links elements after the page loads can cause Google reCAPTCHA to not display, since the element simply does not exist at the time the Google code is executed.
To solve this problem, first make the rendering explicit and pass the function that executes when reCAPTCHA loads:
<script src='https://www.google.com/recaptcha/api.js?onload=recaptchaOnload&render=explicit' async defer></script> Now add a unique identifier to the container, for example.
<div id="recaptcha" class="g-recaptcha" data-sitekey="site key here"></div> Then, in the user-defined function, waiting for the element to 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 continue for 10 seconds until it finds an item and then displays reCAPTCHA in it.
The problem was that it showed most of the time, but sometimes it wasn’t, and I would have to submit a form (and run a validation) to show it. 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