I'm trying to use the ability of google to check if the page request comes from a human or bot. By this I want to include an invisible captcha and submit the verification as soon as the page finishes loading. I've gone through the google docs https://developers.google.com/recaptcha/docs/invisible and the normal example works fine for me. But I'm trying to tweak it in a way the grecaptcha.execute() fires off as soon as the page loads, I've tryied with window.onload, or (window).ready() and I get the same error of
grecaptcha is not defined
Of course I believe it is because the grecaptcha script is not ready, in fact if I set a timeout of 1sec or 2 secs, it will execute fine.
I tried to add the "onload" parameter to the api.js with no luck... and by the way the api.js just includes the actual recaptcha script in the HEAD "recaptcha__en.js"
I do not need an actual FORM or submit any contact information, just need to verify if the subject viewing the page is a human or a bot
any ideas/suggestions will be appreciated! thanks!!
EDIT: adding code as requested:
<html>
<head>
<script>
//called only when I set the timeout
function onSubmit(){
console.log("Submitted")
}
//not being called by the "onload parameter of the api.js script"
function loadCaptcha(){
console.log("loaded")
setTimeout(function(){grecaptcha.execute()},2000)
}
</script>
<script src='https://www.google.com/recaptcha/api.js' async defer></script>
<!--<script src='https://www.google.com/recaptcha/api.js?onload="loadCaptcha"' async defer></script>----it doesnt make any difference for my case-->
</head>
<body>
<div class="g-recaptcha"
data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxxxx"
data-callback="onSubmit"
data-size="invisible">
</div>
<script>
//Window.onload = setTimeout(function(){grecaptcha.execute()},2000) this works!
Window.onload = grecaptcha.execute() //----this doesn't work---//
</script
</body>