Finding reCaptcha callback path using selenium Python

#1
Good morning everyone, I was hoping someone could help me with an issue. I've managed to successfully setup the recaptcha solver and all is well except the following:
Python:
driver.execute_script(f"___grecaptcha_cfg.clients[0].l.l.callback('{response}')")
The path to the callback seems to periodically change. It was .O.O. originally but after a few days it started to fail, I noticed the path had changed to .I.I. I was hoping that I could use Selenium to enumerate through the keys in '___grecaptcha_cfg.clients[0]' and find the path which contains the sitekey and callback function. Therefore, I wouldn't have to worry about it failing unexpectedly in the future.

I see on another thread that Mark Miller linked something similar to this, however it's written in js, which I don't understand (https://gist.github.com/2captcha/2ee70fa1130e756e1693a5d4be4d8c70). I'm relatively new to Python too, so trying to reverse that and write into Python code is beyond me...

Any help would be appreciated!
 
Last edited:

hil

New member
#3
Hey, I am having the same issue. Although I was trying to write it in powershell.
Where you able to write it in Python?
Thanks
 

Mark Miller

2Captcha Engineer
#4
You guys can execute the javascript from my gist in Selenium or any webdriver you use to find the callback path and then use it to submit the token.
and it is still made with execute_script. Use return whateverYouWant call in javascript and catch the returned value with your Python code like:

Python:
result = driver.execute_script("""
    let arg1 = arguments[0]
    let arg2 = arguments[1]
    console.log(arg1)
    return('arg2 value' + arg2)
    """, myArg1, myArg2)
Sorry, I'm really bad in Python, especially in it's indentation nightmare, so I can't guarantee that the example is 100% valid :)
 

hil

New member
#5
Thanks Mark. That was great. I got this working with powershell yeterday and was able to return the value of ___grecaptcha_cfg.clients[0] .
But when I try this morning I get an error "Blocked a frame with origin"

Code:
$result = $browser.executeScript("
let cFunctionPath = ___grecaptcha_cfg.clients[0];
return(cFunctionPath);
    ", "")
I tried to retrace my steps back and see what I did differently, but it keeps throwing the error
 
Last edited:
#6
Thanks Mark. That was great. I got this working with powershell yeterday and was able to return the value of ___grecaptcha_cfg.clients[0] .
But when I try this morning I get an error "Blocked a frame with origin"

Code:
$result = $browser.executeScript("
let cFunctionPath = ___grecaptcha_cfg.clients[0];
return(cFunctionPath);
    ", "")
I tried to retrace my steps back and see what I did differently, but it keeps throwing the error

I think you need to google a bit about Blocked a frame with origin error and browser flags like --disable-web-security
 
#7
I think you need to google a bit about Blocked a frame with origin error and browser flags like --disable-web-security
I did and found a few references. I believe I need to specify a different URL that the current url. Its not clear though what URL I need to specify. Is that a google url that has a ___grecaptcha path. Also how should I specify the new URL in the code above. Thanks
 
#8
I did and found a few references. I believe I need to specify a different URL that the current url. Its not clear though what URL I need to specify. Is that a google url that has a ___grecaptcha path. Also how should I specify the new URL in the code above. Thanks
___grecaptcha is not a URL, it's just a javascript object name
First of all you should understand which your action leads to the error. Without looking into your code and the browser output I can't suggest anything.
 
#9
Thanks Mark. Here is my powershell code:

Code:
Import-Module selenium
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeOptions.AddArguments(@(   "--disable-web-security"))
$browser = New-Object OpenQA.Selenium.Chrome.ChromeDriver($chromeOptions)
$url = "https://www.freepik.com/profile/login"
$browser.Navigate().GoToURL($url)
## --- At this step enter something in the login/password fields so that the captcha section appears --- ##
$browser.executeScript("
let a1 = ___grecaptcha_cfg.clients[0];
return(a1);
    ", "")
The script fails on the RETURN statement with the error "Blocked a frame with origin from accessing a cross-origin frame".
I also added "disable-web-security" to Chrome options when I started it hoping that would disable CORS.
 
Last edited: