reCAPTCHA v3 doesn't return a token when an action ({action: 'action_name'}) is specified as the second argument to grecaptcha.execute

7,297 views
Skip to first unread message

Swapnil Tiwari

unread,
May 29, 2018, 6:12:13 AM5/29/18
to reCAPTCHA
I have integrated reCAPTCHA v3 in my application like so:

  1. Add this script <script src='https://www.google.com/recaptcha/api.js?render=<my_site_key>'></script>
  2. Executed this code after the script loads (I have tried executing it on a button click too):
    grecaptcha.ready(function() {
    grecaptcha.execute('<my_site_key>', {action: 'Page load'})
    .then(function(token) {
    console.log(token)
    });
     
    })
The code in the second line doesn't print the token in the console. The token just comes out to be null. But when I remove the {action: 'Page load'} parameter for the execute method, I do get a token in my console. 

What is the reason for this? The docs don't suggest specifying these actions anywhere but directly in the code.
How do I get the token even with an action?

Cristiano Belloni

unread,
Jun 11, 2018, 8:18:05 AM6/11/18
to reCAPTCHA
This happens to me too. Pretty sure my key is a v3 one, but with any { action }, the token is null. If I specify no { action }, instead, token comes through.

Torgeir Lund

unread,
Jun 18, 2018, 8:23:37 AM6/18/18
to reCAPTCHA
I found out that I had characters not allowed in the action name. Use only a-z, A-Z, and _
Reply all
Reply to author
Forward
0 new messages