8
votes

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.

1
This seems like something you'd find in the docs for using reCAPTCHA.jack
You'd think so but the documentation is very basic.Brian David Berman
Hm. Have you tried making a page with the tag and an invalid sitekey, and watching the dev console?jack
I'd love to know how to improve my question, from whoever downvoted me. Is this not a community? Downvote with no comment? Odd behavior.Brian David Berman
I did some research and I couldn't find a way on how to parse this error. The problem is that the captcha loads inside an iframe with a different domain. If you try to load the captcha data and check that data for errors, then you'll have loading errors due to CORS. There is a way loading the captcha outside the iframe, but it's for v1, not for v2. I think the only way to do this check, is by using a server side script to fetch, parse and check the captcha result for such errors.Christos Lytras

1 Answers

1
votes

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