Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when Recaptcha window is closed

Tags:

recaptcha

I'm facing the following situation: When an user clicks a submit button, the app disables the button. Then, when the callback function of the ReCaptcha is called, I can enable the button again. But if the user closes the verify window how can I know that and then enable my button again?

like image 716
Tenorius Avatar asked Oct 23 '25 20:10

Tenorius


1 Answers

I was facing the same problem using invisible recaptcha. The way I solve it is observing when the captcha was getting closed.

First get the div Element containing the captcha.

let iframe = document.querySelector('iframe[src^="https://www.google.com/recaptcha"][src*="bframe"]');
let container = iframe.parentNode.parentNode;

Then

let observer = new MutationObserver( mutations => {
  if(container && container.style.visibility === 'hidden'){
     // Re enable the button 
  }
});

observer.observe(container, { attributes : true, attributeFilter : ['style'] });
like image 71
Narciso Avatar answered Oct 26 '25 18:10

Narciso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!