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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With