Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test for bad reCAPTCHA sitekey with javascript

Is there a way to programmatically test (with javascript) whether or not a Google reCAPTCHA sitekey is valid? For example, when an invalid sitekey is provided to reCAPTCHA, the following error message is displayed within the reCAPTCHA widget:

ERROR for site owner: Invalid site key

I'd like to test for this condition in code.

like image 393
Brian David Berman Avatar asked Oct 30 '16 00:10

Brian David Berman


People also ask

How do I test if reCAPTCHA is working?

You can test invisible recaptcha by using Chrome emulator. You will need to add a new custom device (BOT) in developer tools, and set User Agent String to Googlebot/2.1 on Desktop . Then use the new BOT device when testing on your site to trigger the recaptcha authentication.

How do I know if my Google reCAPTCHA key is valid?

on JavaScript it would be something like this: recaptcha_url = 'https://www.google.com/recaptcha/api2/anchor?ar=1&k=' + RECAPTCHA_SITE_KEY + ' &co=' + CO_VALUE + '&hl=en-US&size=invisible'; Then, you perform a GET request on this URL. On PHP, you can use cURL.

How do I check my reCAPTCHA v3?

reCAPTCHA v3 works in the background and doesn't require a CAPTCHA widget to work. If reCAPTCHA v3 is working correctly on the front-end of your site a small reCAPTCHA badge should appear at the bottom right of each page.


1 Answers

Unfortunately Google doesn't give any option for developers to verify a site key, and it cannot be done programmatically with Javascript as recaptcha is an iframe and the frames html code cannot be accessed client-side.

The only possible solution would be to implement some kind of web scraping tool to take a screen capture of the ReCaptcha widget and return a result if the sitekey is valid or not.

A tool that might help can be found here

like image 166
Ben Hili Avatar answered Oct 21 '22 02:10

Ben Hili