0

Unfortunately I have to use VPN to visit google, including recapcha. Some chrome extensions can redirect those to recaptcha.net, otherwise I won't see captcha at all.....works in most cases, but sometimes not. Now I got this site, the source code shows replacement did not happen. It's like:

<div class="gglcptch gglcptch_v3"><input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> <script src="https://www.google.com/recaptcha/api.js?render=6LesAYIUAAAAAMj2s2eUJfWEJNiAZTdeGONG5r5w"></script>
                            <script>
                              grecaptcha.ready(function() {
                                  grecaptcha.execute('6LesAYIUAAAAAMj2s2eUJfWEJNiAZTdeGONG5r5w', {action: 'BWS_reCaptcha'}).then(function(token) {
                                    document.querySelectorAll( "#g-recaptcha-response" ).forEach( elem => ( elem.value = token ) );
                                  });
                              });
                             </script></div>

So I essembled this code:

$(document).ready(function(){

$('.gglcptch gglcptch_v3').html(function(index,html){
    return html.replace(/www\.google\.com\/recaptcha\//g,'recaptcha.net/recaptcha/');
});


}); 

Chrome dev did not show error, but still replacement not happening. So my guess is the sequence? when document.ready, script already done running? What should I do?

0

1 Answer 1

2

1. Your selector is wrong. Should be like the below one:

$('.gglcptch.gglcptch_v3').html(
   // ... your function
)

$(document).ready(function(){

$('.gglcptch.gglcptch_v3').html(function(index,html){
    return html.replace(/www\.google\.com\/recaptcha\//g,'recaptcha.net/recaptcha/');
});

console.log($('.gglcptch.gglcptch_v3 script').attr('src'))

}); 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="gglcptch gglcptch_v3"><input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> <script src="https://www.google.com/recaptcha/api.js?render=6LesAYIUAAAAAMj2s2eUJfWEJNiAZTdeGONG5r5w"></script>
                            <script>
                              grecaptcha.ready(function() {
                                  grecaptcha.execute('6LesAYIUAAAAAMj2s2eUJfWEJNiAZTdeGONG5r5w', {action: 'BWS_reCaptcha'}).then(function(token) {
                                    document.querySelectorAll( "#g-recaptcha-response" ).forEach( elem => ( elem.value = token ) );
                                  });
                              });
                             </script></div>

2. But this won't replace google recaptcha to any other external source.

when document.ready, script already done running?

The answer is: Yes.

3. You should load external script(from recaptcha.net or so). See e.g. this link: JavaScript - function to load external JS files is needed

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. This works! Though I'm still having problem putting it to code (which I'll open another question), I can login now in Chrome Dev - 1st step is $.getScript, 2nd step is grecaptcha.ready(function()...2nd step I got "undefined" but I can login now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.