How Recaptcha 2 is solved
How the Recaptcha 2 solving process works, how the callback is run.
When our extension sees a reCAPTCHA 2 block on a web page (no matter if it's a visible or invisible Recaptcha) it sends an API request to the anti-captcha.com service passing it a Site key and site domain. It waits for an answer as a special Hash. This Hash is placed into invisible <textarea> field near the Recaptcha itself. And then when a webpage form is send, the target website gets this hash and asks Google if it's valid or not. If everything is OK then the website continues it's normal work. The target website may use a special callback function which we will describe later.
There is a special captcha type which looks like a small Recaptcha badge in a right bottom corner of the webpage. It's not required to be solved right away. It usually show up when a submit form button pressed. On this button click action the Google analyzes user behavior. In case of suspicious activity it shows a window where user should chose store fronts, road signs, etc. After passing the test, a Callback function will be called and then the form will be submitted.
For our extension, there is not much difference which type of Recaptcha to solve. In the case of invisible Recapcha there is an opportunity to save some money using the option "Start reCAPTCHA 2 solving only when a challenge box is shown", you can read more about this feature on the page with tips on financial optimization of our extension.
Multiple Recaptchas on a same web page
There can be several Recaptchas on one web page. For example, one for a block with registration, another for authorization, and so on. And most often, all ordinary visible Recaptchas on a webpage have one Site key (a unique key for each domain in the Recaptcha 2 system), and another for an invisible recaptcha. We group all Recaptchas with the same sitekey and send one or two tasks to the anti-captcha.com service (in the case if there is both a regular and invisible recaptcha on the webpage). It saves your money.
Often to complete a Recaptcha solving process it's required not only to provide the hash solution itself, which we get from anti-captcha.com, but also execute a certain JS callback function. Which the owner of the target site have set in the Recaptcha settings as the one that needs to be run after a successful passing the captcha. The so-called Callback function.
Since there can be several Recaptchas on the page, our algorithm automatically determines for which of them this callback should be executed. Moreover, this algorithm uses many factors distributed over the following priorities.
About priorities of calling the callback function for Recaptcha
The main (first) priority is given to the Recaptcha block, which was specified in API request in the solveRecaptcha method. I.e. if you explicitly indicated in the API request that you want to solve this particular Recaptcha, then the callback will almost certainly be called for it, regardless of other factors: whether this block is hidden in the browser or not, etc.
Further, priority is given to the single clearly visible in the browser Recaptcha block. This is the most common case. Since we cannot know for sure which Recaptcha our client has decided to solve, at the moment of the end of the solution, one of them is chosen and it has not to be hidden from the user. If we found one then the callback is run for it. If there is only one single Recaptcha on the page then it should still be visible to the user, otherwise the callback won't be called!
And the Invisible Recaptcha type in our understanding is not hidden from the user. It's icon is still visible in the lower right corner and we interpret it in the same way as usual. But if this icon is specifically completely hidden from the user's eyes in the browser, then this recaptcha is interpreted as hidden and it will not receive priority when we run the callback.
The last priority is given to the Recaptcha that was called with the enabled option "Start reCAPTCHA 2 solving only when a challenge box is shown". That is, if the option is enabled and a challenge box (where you need to select traffic lights or store fronts, etc) appears for some block among any other Recaptchas on the page, then, according to the idea of this option, the captcha solution itself will start. And as a result the callback will be run for this Recaptcha block, but only if the above two conditions are not satisfied (API solveRecaptcha method call or one single visible Recapcha), which have a higher priority.
At this point, all the priorities mentioned above cover most Callaback cases. And at the same time they don't run those unnecessary callbacks. If you have any questions or suggestions, feel free to write your proposal in our feedback form.