reCaptcha v3, delays between grecaptcha.execute().then(callback) invocations

2,490 views
Skip to first unread message

ant...@bu.edu

unread,
Nov 6, 2018, 3:13:06 PM11/6/18
to reCAPTCHA
Hello,

I have an app that sends 3 AJAX requests in parallel on a form submission. Something like:

            $.each(urls, function(i, url) {
                $.ajax(url, {
                                ...
                                callback:function(){}
                });
            });



This works great, all three requests are sent in parallel:



Screen Shot 2018-11-06 at 2.46.12 PM.png



I decided to add reCaptcha v3 scores to each of those requests and ended up with something like this:

            $.each(urls, function(i, url) {
                grecaptcha.execute(CLIENT_KEY, {action: url})
                .then(function(token) {
                    $.ajax(url, {
                                    ...
                                    callback:function(){}
                    });
                });
            });

But this version has a sensible delay between grecaptcha.execute().then() callback invocations:

Screen Shot 2018-11-06 at 2.59.37 PM.png


The delay is about 400-500 ms which in total give an extra second before the third (original) AJAX request is getting sent.

Is this delay by design? Is there any way to avoid having it?

Thank you,

Anton

reCAPTCHA support

unread,
Nov 6, 2018, 6:26:36 PM11/6/18
to reCAPTCHA

We will roll our a fix soon that will improve the performance. However, if you are using a single client that calls to grecaptcha.execute will always run sequentially. For maximum performance you should generate a single token instead of generating 3 at the same time, if this is compatible with your back-end architecture since each token can only be verified once.

Best Regards
-reCAPTCHA Support Team

ant...@bu.edu

unread,
Nov 6, 2018, 7:31:23 PM11/6/18
to reCAPTCHA
Sounds good! Thank you very much for the timely response. So if now 3 grecaptcha.execute calls take 1.5 seconds to finish, should I expect that in the future it will be only ~150 ms? (given that each request to the captcha backend takes ~50 ms to finish)

Unfortunately, the backend doesn't allow to verify a single token because there is nothing there that can store state (such as a db, memcache, etc). Is there a way to instantiate 3 instances of grecaptcha on the front-end to have them working in parallel?

Thanks again,
Anton
Reply all
Reply to author
Forward
0 new messages