google / recaptcha

PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.
http://www.google.com/recaptcha/
BSD 3-Clause "New" or "Revised" License
3.48k stars 770 forks source link

add new event handler: initSuccess #239

Closed rehfeldchris closed 6 years ago

rehfeldchris commented 6 years ago

I want a new event handler named something like "captcha-successfully-displayed" or "initSuccess"

Right now, your api gives us the load event, but this event occurs before the widget is actually rendered. And, once it renders, we don't know what it has rendered: it may render the captcha test, or some error message. So, we have no way to determine if the user has actually been presented with a fully working captcha test. We must assume. We cannot inspect the recaptcha dom due to it being cross origin.

My use case: I use recaptcha v2, and some of my users install web browser extensions such as ad blockers and privacy enhancers such as Ghostery. These can block/interfere with some of the requests recaptcha makes. For example, Ghostery makes one of my user's recaptcha display a "error for site owner: invalid site key". I want to be clear: My site key is fine - their extension (ghostery) interfered and caused that error.

I realize that "users will be users" and their extensions will break stuff. That's fine. But, I want to be able to discover that it's broken. In my case, I wish to present an alternative captcha to them if recaptcha failed.

If there was an event that fired when the captcha renders+inits successfully, I think it would represent good engineering, and many people could use it and their recaptcha integrations would be higher quality as a result. I'm sure there's other unexpected failure scenarios besides my ghostery+site key error.

rowan-m commented 6 years ago

This isn't directly related to the PHP code which is what this repo focuses on. However, you might want to look at the v3 support in the most recent release. That uses a wholly invisible reCAPTCHA that just returns a confidence score for the request. This might alleviate some of your issues. Example hosted at https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php

timeverts commented 4 years ago

@rehfeldchris, 2 years later I have just been working on a project where I've had similar needs as to what you required. It also would have been extremely helpful to have an event to hook into that fires when the v2 reCAPTCHA is rendered successfully. In the end I had to make use of a MutationObserver to achieve what i needed.