ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.62k stars 1.15k forks source link

How to run UC Remotely "driver = webdriver.Remote()" #617

Open Anticope12 opened 2 years ago

Anticope12 commented 2 years ago

Hello team, Fantastic tool. I'm trying to run UC via a remote comand_exceutor="http://SERVIER.IP:4444/wd/hub"

There are the following Threads Already open without any solution.

Looking forward to hearing a workaround for this.

Thank you,

394

462

594

Anticope12 commented 2 years ago

Hi @ultrafunkamsterdam , What a fantastic Solution and thank you for sharing the project. I just noticed there were several threads open here and on Smackover flow. Without any solution in place. I'm wondering if you could guide us to have the remote option available.

sebdelsol commented 2 years ago

Selenium chromedriver and undetected-chromedriver behave quite differently:

So I'm not sure how you'll patch the driver on your remote PC and be sure your browser has been launched first (so that it's initialized just as is your regular browser).

Maybe a better strategy would be to use RPyC ?

Anticope12 commented 2 years ago

Thank you for your input @sebdelsol ! I'll try to figure out a way how to patch it. As I'm running each browser on a docker container to have an isolated session. I'll need to find a way to UC lunch the Chrome and patch the chromedriver. Any thoughts if anyone has done something similar?

gonnsuarez commented 2 years ago

Hi Team, agree with Anticope12, fantastic tool, thanks! Also trying to achieve the same thing here, I'm running a selenium grid with docker containers with some chrome nodes:

https://github.com/SeleniumHQ/docker-selenium/blob/trunk/docker-compose-v3-swarm.yml

and the goal is to include this patch when launching the driver sessions with the line:

driver = webdriver.Remote("http://192.168.0.174:4445/wd/hub")

I'm not so sure how to implement this but maybe we can join forces here and make some something

Anticope12 commented 2 years ago

Hi @gonnsuarez , I'm doing some search and I've found this https://github.com/wkeeling/selenium-wire a Selenium-wire that is supported with a Remote driver. Could you please test it out and let me know if it works?

Chrome and Firefox

For Chrome and Firefox you don't need to do anything special. Just instantiate the webdriver as you would normally with webdriver.Chrome() or webdriver.Firefox() passing in any desired capabilities and browser specific options for Chrome or Firefox , such as the executable path, headless mode etc. Selenium Wire also has it's own options that can be passed in the seleniumwire_options attribute.

Remote

Selenium Wire has limited support for using the remote webdriver client. When you create an instance of the remote webdriver, you need to specify the hostname or IP address of the machine (or container) running Selenium Wire. This allows the remote instance to communicate back to Selenium Wire with its requests and responses.

options = { 'addr': 'hostname_or_ip' # Address of the machine running Selenium Wire. Explicitly use 127.0.0.1 rather than localhost if remote session is running locally. } driver = webdriver.Remote( command_executor='http://www.example.com', seleniumwire_options=options ) If the machine running the browser needs to use a different address to talk to the machine running Selenium Wire you need to configure the browser manually. https://github.com/wkeeling/selenium-wire/issues/220 goes into more detail.

Anticope12 commented 2 years ago

Hi @gonnsuarez , Any news?

gonnsuarez commented 2 years ago

Hi @Anticope12, I'm not sure of understanding how this selenium wire module can help us in the objetive of implementing the undetected chromedriver in a remote computer, I will appreciate if you can explain the idea a little bit further,

Meanwhile, I tried the idea given by @auror44 in this other issue opened https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/594#issuecomment-1102939367

Maybe it's because it applies better in my scenario of running a chrome swarm in selenium grid docker containers. The idea I'm having is being able to use all my normal selenium code, but with the only difference of patching the chromedriver first, when the container is created.

In a simple test i tried this:

https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/594#issuecomment-1149268504

but with no luck, it seems to have no effect, but well, is just the beggning. I will continue following thes opened issues hoping in the short term find some kind of workaround util an official support for remote drivers is launched!

UmutAlihan commented 2 years ago

Still looking very forward to be able to utilize undetected-chromedriver with webdriver.Remote() 🙏

gonnsuarez commented 2 years ago

I've done some further testing trying to adapt calls that uc.Chrome makes on selenium library but I founded that the key problem is what sebdelsol mention in this comment:

https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/617#issuecomment-1116263993

In order to be able to make it work in "remote" mode is necessary to deeply understand how the selenium grid works and try to modify something between these modules and specially the node so in that way the chrome browser launches first and then the chrome driver launches separately, attaches to that browser, and register his session to the event bus and session map.

imagen

I think is not a simply work, maybe someone with a a deep understanding of https://github.com/SeleniumHQ/docker-selenium#fully-distributed-mode---router-queue-distributor-eventbus-sessionmap-and-nodes can help us!

Anticope12 commented 1 year ago

Thank you so much @sebdelsol @gonnsuarez for your explanation and the support 🙇‍♂️ Let's see if we can do it 👍

iQiexie commented 1 year ago

Any news?

gonnsuarez commented 1 year ago

Giving up on this idea I've started working with a windows 10 virtual machine with python, undetected_chromedriver and a little rpyc server that works as kind of "chrome hub" and so far is working great. I know that thinking on a w10 vm sounds like shit but the fact that is only used for the browsers and those browsers are running the more "realistic" way it helps a lot, I do not have to bother with some strange errors or crashes or bot detections. With rpyc you can run your actual scrapping python code wherever you want and the vm is only for browsing.

iamumairayub commented 10 months ago

@sebdelsol

Selenium chromedriver and undetected-chromedriver behave quite differently:

  • Selenium chromdriver launches first, then launches the browser.
  • undetected-chromedriver launches Chrome first, then download and randomly patches the chromedriver, launches it & connects to the browser.

So I'm not sure how you'll patch the driver on your remote PC and be sure your browser has been launched first (so that it's initialized just as is your regular browser).

Maybe a better strategy would be to use RPyC ?

Can you share more information on how you did it? code samples?