-
-
Save 2captcha/2ee70fa1130e756e1693a5d4be4d8c70 to your computer and use it in GitHub Desktop.
A piece of javascript code that can help you to find reCAPTCHA parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IMPORTANT! PLEASE READ BEFORE USING THIS: | |
// | |
// 1. This is JavaScript. JavaScript is executed in a browser. | |
// You can execute javascript when you control a browser with some browser automation tools. | |
// To execute javascript from your code use the corresponding method provided by your tool, for example: | |
// JavascriptExecutor interface in Selenium Java | |
// ExecuteJavaScript method of WebDriver in Selenium for .Net | |
// page.evaluate method in puppeteer | |
// Please refer to docs of your favourite browser automation tool for more info | |
// | |
// 2. If you don't understand what UNDEFINED means in the javascript console, please read: | |
// When you execute the code in the javascript console of your browser, the console evaluates EACH expression | |
// and prints the returned value. And if your expression does not return any value (that is absolutely normal) | |
// then you see 'undefined' in the console. This is NOT AND ERROR! | |
// | |
// For better understanding type the following in the console: | |
// let myVar = 'foo' // defines myVar variable and sets it's value to 'foo' | |
// You will see undefined in the console as this exression does not return anything. | |
// | |
// Then type the following | |
// (() => 'bar')() // defines and calls a function that returns 'bar' | |
// You will see "bar" as the function returns this value | |
// | |
// And one more case. Type: | |
// ((a) => { b = a * 2 })(2) // defines and calls a function that does not return any value | |
// What you will see? Yep, you will see undefined | |
// | |
// Hope now you understand some javascript console basics :) | |
// | |
// 3. The callback can be not the final step in your process. That is fine when after the callback you also need to perform | |
// another action like button click, form submission, etc | |
// | |
// 4. NO, we can't make the same script for hCaptcha as the callback is not defined inside globaly accessible variables. | |
// USAGE | |
// paste the function definition into the console and then call the function: | |
// | |
// let res = findRecaptchaClients() | |
// console.log(res) | |
// | |
// the function returns an array of objects with recaptcha parameters for each implementation found on the page | |
function findRecaptchaClients() { | |
// eslint-disable-next-line camelcase | |
if (typeof (___grecaptcha_cfg) !== 'undefined') { | |
// eslint-disable-next-line camelcase, no-undef | |
return Object.entries(___grecaptcha_cfg.clients).map(([cid, client]) => { | |
const data = { id: cid, version: cid >= 10000 ? 'V3' : 'V2' }; | |
const objects = Object.entries(client).filter(([_, value]) => value && typeof value === 'object'); | |
objects.forEach(([toplevelKey, toplevel]) => { | |
const found = Object.entries(toplevel).find(([_, value]) => ( | |
value && typeof value === 'object' && 'sitekey' in value && 'size' in value | |
)); | |
if (typeof toplevel === 'object' && toplevel instanceof HTMLElement && toplevel['tagName'] === 'DIV'){ | |
data.pageurl = toplevel.baseURI; | |
} | |
if (found) { | |
const [sublevelKey, sublevel] = found; | |
data.sitekey = sublevel.sitekey; | |
const callbackKey = data.version === 'V2' ? 'callback' : 'promise-callback'; | |
const callback = sublevel[callbackKey]; | |
if (!callback) { | |
data.callback = null; | |
data.function = null; | |
} else { | |
data.function = callback; | |
const keys = [cid, toplevelKey, sublevelKey, callbackKey].map((key) => `['${key}']`).join(''); | |
data.callback = `___grecaptcha_cfg.clients${keys}`; | |
} | |
} | |
}); | |
return data; | |
}); | |
} | |
return []; | |
} |
wassup everyone i trying to solve capthca via seleinum python i got error ___grecaptcha_cfg is not a function and i tried to exeucte token via
document.getElementById("g-recaptcha-response").innerHTML="{token}"; not work also anyone have an idea to help me please
callback : "___grecaptcha_cfg.clients['0']['D']['D']['callback']"
function : "onCaptchaSuccess"
id : "0"
pageurl : "https://example.com"
sitekey : "6LcfWgIqAAAAAIMMEhI1qOognQxpDZ1aj80pvJdW"
Hi. I used the script and it work fine.
I found multiple callback with version V2 and V3, I must check they separately by multiple request to 2captcha?
I really need help to solve this enterprise captcha. Anyone have any ideas? I already tried
const frameReCaptcha = page
.frames()
.find((frame) => frame.url().includes('recaptcha/enterprise/anchor'))
// Gets key
const reCaptchaKey = jsonUtil.urlToObject(frameReCaptcha.url()).k
const captchaTaskObj = {
clientKey: 'mykey (omitted',
task: {
type: 'RecaptchaV2EnterpriseTaskProxyless',
websiteURL: 'https://www.rtdbrasil.org.br/',
websiteKey: reCaptchaKey,
// "enterprisePayload": {
// "s": "SOME_ADDITIONAL_TOKEN"
// }
},
}
console.log(captchaTaskObj, 'console log of captchaTaskObj')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, I didn't quite understand your question