Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// usage: let res = findRecap()
// console.log(res)
// returns an array of objects with recaptha parameters for each implementation found on the page
const findRecap = () => {
if (typeof (___grecaptcha_cfg) !== 'undefined') {
let cs = []
for (let id in ___grecaptcha_cfg.clients) {
cs.push(id)
}
let res = cs.map(cid => {
for (let p in ___grecaptcha_cfg.clients[cid]) {
let c = {}
cid >= 10000 ? c.version = 'V3' : c.version = 'V2'
let path = "___grecaptcha_cfg.clients[" + cid + "]." + p
let pp = eval(path)
if (typeof pp === 'object') {
for (let s in pp) {
let subpath = "___grecaptcha_cfg.clients[" + cid + "]." + p + "." + s
let sp = eval(subpath)
if (sp && typeof sp === 'object' && sp.hasOwnProperty('sitekey') && sp.hasOwnProperty('size')) {
c.sitekey = eval(subpath + '.sitekey')
if (c.version === 'V2') {
let cb = eval(subpath + '.callback')
if (cb == null) {
c.callback = null
c.function = null
}
else {
c.callback = subpath + '.callback'
cb != c.callback ? c.function = cb : c.function = null
}
} else {
let cb = eval(subpath+'["promise-callback"]')
if (cb == null) {
c.callback = null
c.function = null
}
else {
c.callback = subpath + '["promise-callback"]'
cb != c.callback ? c.function = cb : c.function = null
}
}
}
}
}
return c
}
})
return (res)
} else {
return (null)
}
}
@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Jun 12, 2020

Thanks, much appreciated 👍

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Oct 28, 2020

When this script is run in the console (Chrome - Dev Tools) it returns undefined. Is it still working?

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Oct 29, 2020

@hdsouza try using "___grecaptcha_cfg.clients[0]" in console to find the captcha

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Oct 29, 2020

Thanks @khaelou.

Yes, I opened the site in Firefox and did an inspect element
In the console if I type "___grecaptcha_cfg.clients". I see 2 clients. Which one do i select? 0 or 100000

image

If I select 0 then.. Is this the correct path.. "___grecaptcha_cfg.clients[0].A.A." ..or do i need to go into some of the other letters below, like G, N etc. I was going with A.A as I see that it has the same sitekey value as I would need to use when I would request for the captcha response.

image

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Oct 29, 2020

@hdsouza Yes always use ___grecaptcha_cfg.clients[0], from previous experience please remember that the Object letter may change over time. For example ___grecaptcha_cfg.clients[0].A.sitekey may become ___grecaptcha_cfg.clients[0].K.sitekey another day. So again, it'll always be the object which contains the sitekey.

@kratzky

This comment has been minimized.

Copy link

@kratzky kratzky commented Nov 2, 2020

Thanks @khaelou.

Yes, I opened the site in Firefox and did an inspect element
In the console if I type "___grecaptcha_cfg.clients". I see 2 clients. Which one do i select? 0 or 100000

image

If I select 0 then.. Is this the correct path.. "___grecaptcha_cfg.clients[0].A.A." ..or do i need to go into some of the other letters below, like G, N etc. I was going with A.A as I see that it has the same sitekey value as I would need to use when I would request for the captcha response.

image

In most cases:
[0] is V2/V2 invisible
[100000] is V3

and even in really rare cases there are multiple implementations of each version with indexes like [1], [2] or [100001], [100002]

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Nov 2, 2020

So what should the call back in this case: "___grecaptcha_cfg.clients[0].A.A.callback(CapthcaResponse) ?

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Nov 2, 2020

@hdsouza ___grecaptcha_cfg.clients[0].A.A.callback(CapthcaResponse) is correct way to call callback in your case

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Nov 3, 2020

@khaelou I have tried that command from Firefox - devtools - console and it does not send the response across. There is no activity on page to signify that the command did anything. Do I need to specify the name of the callback function "bound " somehow?

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Nov 3, 2020

@hdsouza That's odd, yet I'm not sure about Firefox since I've been using Chrome. Try running from Chrome Dev Tools Console and see if that makes a difference. The name of callback or what goes in the '' of the callback() function is the solved token key that is generated from 2captcha.com

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Nov 6, 2020

Thanks @khaelou . I just realized it was working all along. The callback command was being sent correctly but I was looking for a check-mark of captcha acceptance which I was not seeing, but when I just tried clicking on the login button, it went right through. Thanks for prodding me in the right direction :) .. That being said, is there a command that will validate that the captcha has been accepted.. something like grecaptcha.getResponse (I realize its not relevant to the main topic).

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Nov 16, 2020

@hdsouza Yes, yet it isn't exactly a command. You should refer to the documentation of your provided captcha solving service (2captcha) which usually provide endpoints for verification/error-handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.