Open torzak opened 1 year ago
I figured out how to do it, I'll post a gist here with the solution.
@torzak any update on this - interested!
@talvbansal
You can get a RemoteWebdriver Object connected to an existing session like that :
$driver = RemoteWebDriver::createBySessionID(
'xxxxxxxxxx__SESSION_ID__xxxxxxxxx',
'http://localhost:5444',
0,
0,
true,
DesiredCapabilities::chrome()
);
Please look at the source code of the RemoteWebDriver::createBySessionID function. It has two "hidden" parameters that are not declared in its signature.
public static function createBySessionID(
$session_id,
$selenium_server_url = 'http://localhost:4444/wd/hub',
$connection_timeout_in_ms = null,
$request_timeout_in_ms = null
) {
// BC layer to not break the method signature
$isW3cCompliant = func_num_args() > 4 ? func_get_arg(4) : true;
$existingCapabilities = func_num_args() > 5 ? func_get_arg(5) : null;
$executor = new HttpCommandExecutor($selenium_server_url, null, null);
if ($connection_timeout_in_ms !== null) {
$executor->setConnectionTimeout($connection_timeout_in_ms);
}
if ($request_timeout_in_ms !== null) {
$executor->setRequestTimeout($request_timeout_in_ms);
}
if (!$isW3cCompliant) {
$executor->disableW3cCompliance();
}
// if capabilities were not provided, attempt to read them from the Selenium Grid API
if ($existingCapabilities === null) {
$existingCapabilities = self::readExistingCapabilitiesFromSeleniumGrid($session_id, $executor);
}
return new static($executor, $session_id, $existingCapabilities, $isW3cCompliant);
}
Let me know whether it works for you or not. I can help you if it doesn't.
@torzak I was looking for this way to connect UC with php webdriver. I am using latest php-webdriver and trying to connect UC. I am able to connect but none event of php-webdriver is working. Like opening URL OR getting active element. Active element throwing error because jsonwire is expecting array and event is sending element as string
Can you please help
Hey @torzak Hope you can help me :) I'm trying to control a UC session I created via PHP Webdriver with your code like that in python:
from multiprocessing import freeze_support
import undetected_chromedriver as uc
import time
if __name__ == '__main__':
freeze_support()
options = uc.ChromeOptions()
options.debugger_address = "localhost:4444"
options.add_argument('--proxy-server=http://127.0.0.1:8080')
options.add_argument('--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/124.0 Safari/537.36')
driver = uc.Chrome(options=options)
print(driver.session_id)
print('-')
print(driver.options.debugger_address)
And PHP code is:
<?php
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
$driver = RemoteWebDriver::createBySessionID(
'my_session_id',
$serverUrl,
0,
0,
true,
DesiredCapabilities::chrome()
);
print_r ($driver);
$driver->quit();
?>
But I'm getting an empty response error: PHP Fatal error: Uncaught Facebook\WebDriver\Exception\Internal\UnexpectedResponseException: JSON decoding of remote response failed. Error code: 4 The response: ''
Can you help me to figure out what's the problem? Thanks a lot!
My goal is to run Undetected-Chromedriver sessions in Python and then take control of the browser with php and phpwebdriver.
I start by running the following code in Python:
Then, I try to establish a connection to the session and defined debugger_address using phpwebdriver. However, it appears that phpwebdriver receive an empty response from http://127.0.0.1:5444/
Any help or suggestions would be appreciated. Thank you.