How to refresh token google recaptcha v3 (hidden recaptcha supported)

Google recaptcha V3 support reload token without Reload Pages.

reCaptcha V3 in an invisible captcha, it automagically detects user behaviors and rate it, no need to reload or user's direct interaction with any UI.

reCAPTCHA v3 returns a score for each request without user friction. The score is based on interactions with your site and enables you to take an appropriate action for your site.

reCAPTCHA v2 reset

grecaptcha.reset();

reCAPTCHA v3 reset

Calling the grecaptch.execute() function that gets rendered on the page , will reset the value by the looks. (Google Recaptcha V3 - Widget Id when loading captcha through URL)

grecaptcha.execute('[Your recaptcha ID]', {
    action: 'general_form_contact_us'
}).
then(function(token) {
    document.querySelector('.g-recaptcha-response-v3-contact_us').value = token;
});

Note you will need to adjust all your values accordingly.

You can test it by copying this and pasting in the chrome console. After pressing enter it then changes the value of the hidden field.

Solution

simple solution for refreshing hidden google recaptcha v3, using below codes:

const g_site_key = "YOUR GOOGLE RECAPTCHA V3 SITE KEY";
grecaptcha.execute(g_site_key, { action: "homepage" }).then(function (token) {
  if (location.host == "cdpn.io") {
    var pr = $("pre#token");
    if (pr.length) {
      pr.text(token);
    }
  }
  
  console.log('the new token is', token);
});

FULL DEMO:

See the Pen Complete Google recaptcha v3 by dimas lanjaka (@dimaslanjaka) on CodePen.