Recaptcha has a onload
callback that will run once recaptcha is loaded. Place your code inside that callback function.
https://developers.google.com/recaptcha/docs/display
<script>
function onloadCallback() {
/* Place your recaptcha rendering code here */
}
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"></script>