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.58k stars 1.14k forks source link

How to Set and Connect to Debugging port #966

Open ManabBala opened 1 year ago

ManabBala commented 1 year ago

This is my old code:

# session initialiser
opt = Options();
opt.add_argument("--remote-debugging-port=8989");
opt.add_argument("--user-data-dir=C:\\chromedriver\\chromeProfile");
service_obj = Service("C:\\chromedriver\\chromedriver.exe");
driver = Chrome((service = service_obj), (options = opt));
# realtime debugger
opt = Options()
opt.add_experimental_option("debuggerAddress", "localhost:8989")
service_obj = Service('C:\\chromedriver\\chromedriver.exe')
driver = webdriver.Chrome(service=service_obj, options=opt)

what i do with this:

  1. initiate a browser with a static port number.
  2. run a separate code to connect to the previous session.
  3. With this i don't need to relaunch chrome instance every time i debug
  4. with this i can fast forward the initial going to the page, navigate to desired location find element(need the debugger here) and debug my xpath or anything else fast.

can't Do this with Undetected chromedriver:

  1. can't set the custom port.
  2. can't even connect with the port mentioned in the UC session.

What I need:

  1. A way to do the same(like my old code) with undetected chromedriver
xjxckk commented 1 year ago

Start the browser on the port then use this:

import os
import undetected_chromedriver as uc

options = uc.ChromeOptions()
options.debugger_address = '127.0.0.1:9222'
driver = uc.Chrome(options=options)
os.kill(driver.browser_pid, 15)

undetected-chromedriver connects to the existing browser then starts a browser on a random port, this closes the random browser

aspeed98 commented 1 year ago

You actually can connect to a uc driver, just start a uc driver, then get get it debugaddress: driverToBeControlled = uc.Chrome() debugaddress = driverToBeControlled.options.debugger_address then save it to a file, or just copy paste it and start another uc driver opt = uc.ChromeOptions() # or default selenium ChromeOptions opt.debugger_address = debugaddress driverThatControls = uc.Chrome(options= opt) # or default selenium ChromeDriver Than you can send commands to driverThatControls, and driverToBeControlled will actually execute them. Problem is, by doing so, your driver becomes not secure, and sites see it as a Selenium controlled driver.