How does grecaptcha.execute().then() handle network exceptions?

1,093 views
Skip to first unread message

Alexander R.

unread,
Sep 3, 2019, 6:58:25 PM9/3/19
to reCAPTCHA

Figured I'd ask since reading obfuscated code is a pain...

So say recaptcha service is down (or blocked) - will a user still be able to submit a form given the following snippet:

    var onSubmit = function () {
grecaptcha.execute('@ReCaptchaSiteKey', { action: 'register' }).then(function (token) {
window.document.getElementById('ReCaptchaToken').value = token;
$('form').submit();
});
};


In another words: does the .then() function fire if there was an exception, or is there another undocumented onError() callback that I need to use to submit the form without a token?

Thank you!

Ctibor Laky

unread,
Sep 5, 2019, 5:29:29 PM9/5/19
to reCAPTCHA
Hi Alexander, 

.then() method takes second, undocumented parameter, syntax of the method looks like this:
then(sucessfulCallback: (token: string) => void, failureCallback: (error: Error) => void)): this
but mostly you get `null` in failureCallback parameter, so you are not able to distinguish between network error, or wrong siteKey, or domain not included for siteKey and many other problems.
But at least you are notified that something went wrong and you can take an action.
Good luck! :)

Ctibor
Reply all
Reply to author
Forward
0 new messages