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

Chromium is not closed when calling "driver.quit()"

Open 2uanDM opened this issue 1 year ago • 11 comments

Hi everybody, I has this problem with the newest version of uc: image This image is my option for creating the driver (That browser path is of chromium 114, since my current chrome version is 116)

After executing script, my is closed but I still see chromium active in task manager, and also used a lot of resouces (high cpu usage)

image

I have called driver.quit() at the end but it seem not work in this case. Can anyone help me this my problem ?

2uanDM avatar Aug 24 '23 18:08 2uanDM

After the last updates with chrome 116 the chrome instances do not close correctly, you can try with

subprocess.run(["taskkill", "/F", "/IM", "chrome.exe"], check=True)

This command is working for me with no problems and avoids cpu and ram saturation.

vyanezz avatar Aug 24 '23 18:08 vyanezz

After the last updates with chrome 116 the chrome instances do not close correctly, you can try with

subprocess.run(["taskkill", "/F", "/IM", "chrome.exe"], check=True)

This command is working for me with no problems and avoids cpu and ram saturation.

Thank you very much, it also worked for me

2uanDM avatar Aug 25 '23 00:08 2uanDM

So this is a problem with chrome 116? The proposed solution here isn't viable for me because sometimes I have multiple scripts running at once. If I use subprocess to kill chrome, I'd kill all my scripts.

trestlesky avatar Aug 25 '23 18:08 trestlesky

I'm not quite sure which one of these arguments solves this issue, but this doesn't occur when launched with these:

options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-renderer-backgrounding")
options.add_argument("--disable-background-timer-throttling")
options.add_argument("--disable-backgrounding-occluded-windows")
options.add_argument("--disable-client-side-phishing-detection")
options.add_argument("--disable-crash-reporter")
options.add_argument("--disable-oopr-debug-crash-dump")
options.add_argument("--no-crash-upload")
options.add_argument("--disable-gpu")
options.add_argument("--disable-extensions")
options.add_argument("--disable-low-res-tiling")
options.add_argument("--log-level=3")
options.add_argument("--silent")

@trestlesky @2uanDM

So this is a problem with chrome 116? The proposed solution here isn't viable for me because sometimes I have multiple scripts running at once. If I use subprocess to kill chrome, I'd kill all my scripts.

I'm using chromium browser 114 and it can not always quit the chromium process when I called "driver.quit()". Since my script just running one process so that solution is just temporary

2uanDM avatar Aug 29 '23 14:08 2uanDM

I'm not quite sure which one of these arguments solves this issue, but this doesn't occur when launched with these:

options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-renderer-backgrounding")
options.add_argument("--disable-background-timer-throttling")
options.add_argument("--disable-backgrounding-occluded-windows")
options.add_argument("--disable-client-side-phishing-detection")
options.add_argument("--disable-crash-reporter")
options.add_argument("--disable-oopr-debug-crash-dump")
options.add_argument("--no-crash-upload")
options.add_argument("--disable-gpu")
options.add_argument("--disable-extensions")
options.add_argument("--disable-low-res-tiling")
options.add_argument("--log-level=3")
options.add_argument("--silent")

@trestlesky @2uanDM

Thank you @trestlesky, let's me try this

2uanDM avatar Aug 29 '23 14:08 2uanDM

I'm not quite sure which one of these arguments solves this issue, but this doesn't occur when launched with these:

options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-renderer-backgrounding")
options.add_argument("--disable-background-timer-throttling")
options.add_argument("--disable-backgrounding-occluded-windows")
options.add_argument("--disable-client-side-phishing-detection")
options.add_argument("--disable-crash-reporter")
options.add_argument("--disable-oopr-debug-crash-dump")
options.add_argument("--no-crash-upload")
options.add_argument("--disable-gpu")
options.add_argument("--disable-extensions")
options.add_argument("--disable-low-res-tiling")
options.add_argument("--log-level=3")
options.add_argument("--silent")

@trestlesky @2uanDM

Thank you @trestlesky, let's me try this

This does seem to be working for now, though I tried playing around with the different options, and like you I have no idea which options did the trick.

trestlesky avatar Sep 02 '23 15:09 trestlesky

Unset the --no-sandbox Chrome argument, setting no_sandbox argument of uc.Chrome to False, because it is set to True by default. Example:

uc.Chrome(driver_executable_path=driver_executable_path, options=options, user_data_dir=user_data_dir, no_sandbox=False, user_multi_procs=True, use_subprocess=False)

But some things to consider: Users say that undetected-chromedriver doesn't work without --no-sandbox Chrome argument on Windows 7 and lower, but works on Windows 8.1 and above. I didn't tested that for myself, but I think it's true. Also, undetected-chromedriver most of the times doesn't work on Linux without --no-sandbox Chrome argument(when running test script as root user for example). So, that's because no_sandbox argument of uc.Chrome is set to True by default. Concluding that, set no_sandbox argument of uc.Chrome to False for Windows, and set to True for Linux. But I warn that undetected-chromedriver has breached no_sandbox functionality, so --no-sandbox is always set, whether or not you set it to True or False. I've made pull request to fix it, so we need to wait until it is applied(or download my fork, and use as custom Python module). https://github.com/ultrafunkamsterdam/undetected-chromedriver/pull/1542

Mister-Stein avatar Sep 04 '23 13:09 Mister-Stein

Unset the --no-sandbox Chrome argument, setting no_sandbox argument of uc.Chrome to False, because it is set to True by default. Example:

uc.Chrome(driver_executable_path=driver_executable_path, options=options, user_data_dir=user_data_dir, no_sandbox=False, user_multi_procs=True, use_subprocess=False)

But some things to consider: Users say that undetected-chromedriver doesn't work without --no-sandbox Chrome argument on Windows 7 and lower, but works on Windows 8.1 and above. I didn't tested that for myself, but I think it's true. Also, undetected-chromedriver most of the times doesn't work on Linux without --no-sandbox Chrome argument(when running test script as root user for example). So, that's because no_sandbox argument of uc.Chrome is set to True by default. Concluding that, set no_sandbox argument of uc.Chrome to False for Windows, and set to True for Linux. But I warn that undetected-chromedriver has breached no_sandbox functionality, so --no-sandbox is always set, whether or not you set it to True or False. I've made pull request to fix it, so we need to wait until it is applied(or download my fork, and use as custom Python module). #1542

is worked!

anqi-zhao avatar Nov 22 '23 09:11 anqi-zhao

@dangsonwheredidyoufindthis I tested it and disable gpu is that one argument. No idea why its that tho options.add_argument("--disable-gpu")

11AnJo avatar Jan 11 '24 16:01 11AnJo

The only way I fixed this issue was calling close() before quit() like:

driver.close()
driver.quit()

0x1991 avatar May 04 '24 10:05 0x1991