I am currently working on implementing reCAPTCHA into my project, but I'm facing some challenges with understanding how to effectively utilize it.
Below is the way I'm importing the script:
public loadScript() {
let body = <HTMLDivElement>document.body;
let script = document.createElement('script');
script.innerHTML = '';
script.src = 'https://www.google.com/recaptcha/api.js';
script.async = true;
script.defer = true;
body.appendChild(script);
}
After calling this function in the component constructor, the reCAPTCHA is properly rendered and functional. However, I'm unsure of how to obtain a response from it for my backend.
I attempted to use grecaptcha.getResponse()
, but sometimes encounter a
ReferenceError: "grecaptcha is not defined"
. How can Typescript recognize what grecaptcha is?