Finding reCaptcha callback path using selenium Python

Bunny1327

New member
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:
  • Like
Reactions: hil

hil

New member
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
Staff member
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 :)
 
  • Like
Reactions: hil

hil

New member
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:

Mark Miller

2Captcha Engineer
Staff member
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
 
  • Like
Reactions: hil

hil

New member
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
 

Mark Miller

2Captcha Engineer
Staff member
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.
 
  • Like
Reactions: hil

hil

New member
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:

hil

New member
I finally figured it out (for anyone having the same issue).
In the script above I was trying to RETURN the Path to the function, but the script was actually trying to RETURN the output of the path and not the path itself.

So to return the first item it would be :
Code:
$browser.executeScript("
  let list0 = ___grecaptcha_cfg.clients;
  Callback_Str = ''
  for (let item1 of Object.keys(list0))
    {
    let list1 = ___grecaptcha_cfg.clients[item1];
    //iterate through and find the correct path
    Callback_StrVal = '___grecaptcha_cfg.clients[' + item1 + '].' ;
    break;
    }

   return(Callback_StrVal)
   ", "")
 

brizeljohn

New member
The script fails on the RETURN statement with the error "Blocked a frame with origin from accessing a cross-origin frame".
This error "Blocked a frame with origin from accessing a cross-origin frame " is not a bug. The same-origin policy is a security mechanism that ensures that window objects only have access to the informations they are authorized to get.

The window.postMessage() method provides a controlled mechanism to securely circumvent this Same-Origin Policy restriction. The window.postMessage() safely enables cross-origin communication between Window objects; e.g: between a page and an iframe embedded within it.

Code:
postMessage(message, targetOrigin)
postMessage(message, targetOrigin, [transfer])

targetOrigin - specifies what the origin of targetWindow must be for the event to be dispatched, either as the literal string "*" (indicating no preference) or as a URI.