undetected-chromedriver icon indicating copy to clipboard operation
undetected-chromedriver copied to clipboard

Debug mode error

Open guidetuanhp opened this issue 2 years ago • 10 comments

Capture

import time
import undetected_chromedriver as uc
from selenium.webdriver.chrome.options import Options
if __name__ == '__main__':
    options = Options()
    options.debugger_address = "127.0.0.1:9222"
    driver = uc.Chrome(driver_executable_path='C:\\Users\\guide\\Downloads\\chromedriver.exe', options=options)
    driver.get("https://abrahamjuliot.github.io/creepjs/")
    time.sleep(1000)

When I run with debug mode, it will run 2 chromes the same as the picture. Anyone can show me a method to fix it? Thank you

guidetuanhp avatar Jun 29 '22 02:06 guidetuanhp

  • You should use uc.ChromeOptions() instead of the Selenium one.
  • Why do you need to specify a debug address ? UC already looks for a free port for you...
  • There's a bug indeed with options.debugger_address which is not reflected in the debugger address and port. To fix it you'll have to modify the code in __init__.py, line 250 :
        # debug_port = selenium.webdriver.common.service.utils.free_port()
        # debug_host = "127.0.0.1"

        # if not options.debugger_address:
        #     options.debugger_address = "%s:%d" % (debug_host, debug_port)

        # FIX : REPLACED BY

        if not options.debugger_address:
            debug_port = port if port != 0 else selenium.webdriver.common.service.utils.free_port()
            debug_host = "127.0.0.1"
            options.debugger_address = "%s:%d" % (debug_host, debug_port)
        else:
            debug_host, debug_port = options.debugger_address.split(":")
            debug_port = int(debug_port)

        # END of FIX

EDIT : Or you can use my fork where this bug has been fixed.

sebdelsol avatar Jun 29 '22 09:06 sebdelsol

  • You should use uc.ChromeOptions() instead of the Selenium one.
  • Why do you need to specify a debug address ? UC already looks for a free port for you...
  • There's a bug indeed with options.debugger_address which is not reflected in the debugger address and port. To fix it you'll have to modify the code in __init__.py, line 250 :
        # debug_port = selenium.webdriver.common.service.utils.free_port()
        # debug_host = "127.0.0.1"

        # if not options.debugger_address:
        #     options.debugger_address = "%s:%d" % (debug_host, debug_port)

        # FIX : REPLACED BY

        if not options.debugger_address:
            debug_port = port if port != 0 else selenium.webdriver.common.service.utils.free_port()
            debug_host = "127.0.0.1"
            options.debugger_address = "%s:%d" % (debug_host, debug_port)
        else:
            debug_host, debug_port = options.debugger_address.split(":")
            debug_port = int(debug_port)

        # END of FIX

EDIT : Or you can use my fork where this bug has been fixed.

It still opened 2 chromes the same as the picture. Chrome 1 can remote port to debug. Chrome 2 did not do anything, just opened. Can you have any video showing me the method to fix it?

I have run cmd with "C:\Program Files\Google\Chrome\Application\chrome.exe" -remote-debugging-port=9222 --user-data-dir="D:\test" Then I run my code:

import undetected_chromedriver as uc
if __name__ == '__main__':
    options =uc.ChromeOptions()
    options.debugger_address = "127.0.0.1:9222"
    driver = uc.Chrome(options=options)
    driver.get("https://abrahamjuliot.github.io/creepjs/")
    time.sleep(100000)
    driver.close()

guidetuanhp avatar Jun 29 '22 16:06 guidetuanhp

Sure you launch twice your chrome, once with cmd and a second time with uc.Chrome() in your script !! And by the way the correct command line switch is --remote-debugging-port...

Anyway you don't have to launch a chrome by hand or specify an address or a port :

import undetected_chromedriver as uc

if __name__ == '__main__':
    driver = uc.Chrome()
    driver.get("https://abrahamjuliot.github.io/creepjs/")
    input("hit a key to quit")
    driver.quit()

Thanks for closing this non issue.

sebdelsol avatar Jun 29 '22 16:06 sebdelsol

Sure you launch twice your chrome, once with cmd and a second time with uc.Chrome() in your script !! And by the way the correct command line switch is --remote-debugging-port...

Anyway you don't have to launch a chrome by hand or specify an address or a port :

import undetected_chromedriver as uc

if __name__ == '__main__':
    driver = uc.Chrome()
    driver.get("https://abrahamjuliot.github.io/creepjs/")
    input("hit a key to quit")
    driver.quit()

Thanks for closing this non issue.

But when I run this code

from selenium import webdriver
option = webdriver.ChromeOptions()
option.debugger_address = "127.0.0.1:9222"
driver = webdriver.Chrome(executable_path= 'C:\\Users\\guide\\Downloads\\chromedriver.exe', options=option)
driver.get("https://abrahamjuliot.github.io/creepjs/")
time.sleep(1000)

it only opened 1 chrome. My aim is to control chrome in cmd and not open more chrome browser.

guidetuanhp avatar Jun 29 '22 18:06 guidetuanhp

Why would you want to do that ?!

sebdelsol avatar Jun 29 '22 18:06 sebdelsol

Why would you want to do that ?!

I want to remote gologin profile by undetect_chromedriver.

guidetuanhp avatar Jun 29 '22 18:06 guidetuanhp

why don't you use the Chrome browser launched and controlled by UC for that ? Sorry it doesn't make sense.

sebdelsol avatar Jun 29 '22 19:06 sebdelsol

why don't you use the Chrome browser launched and controlled by UC for that ? Sorry it doesn't make sense.

gologin can fake all fingerprint browsers and I want to remote it.

guidetuanhp avatar Jun 29 '22 21:06 guidetuanhp

I guess it's possible but it would mean a lot of change in UC because there are some conflicts between the 2 packages. UC does launch a Chrome browser in a detached process and handles it's termination. So you'll have to get rid of all this code to make it works. Then you'll have to check that UC options do not conflict with the one added in the package you mentioned, especially everything about user_data_dir, address, host and port. I'm not sure it's worth it since one interesting UC feature is that it starts a pristine browser in a detached process and that comes with a price : experimental options (except prefs) won't work... If I were you I'd ask for help to the gologin owners, their service is not free so it should come with actual support. EDIT : please close this issue, it has nothing to do with UC.

sebdelsol avatar Jun 30 '22 09:06 sebdelsol

Duplicate of #461

sebdelsol avatar Jul 04 '22 10:07 sebdelsol

@guidetuanhp Have you solved the problem yet I also need to control the open browser and have the same problem as you

fomsun avatar Feb 03 '23 08:02 fomsun

@guidetuanhp @fomsun I fixed it, pm me

hoanm1206 avatar Apr 08 '23 17:04 hoanm1206

@hoanm1206 How you fix it? Can you pm me? Discord: WhySoSerious#2434

BeMoreHappY avatar Apr 25 '23 16:04 BeMoreHappY

@guidetuanhp @fomsun @hoanm1206 did u guys found how to do it? I'm really struggling to find a fix

jay-sync avatar Apr 28 '23 16:04 jay-sync