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

undetected chrome driver crashes when using "prefs" to set download behaviour

Open dornech opened this issue 1 year ago • 2 comments

I use webscraping for some downloading stuff and was trying to incorporate undeteced-chromedriver. To control the behaviour I use the prefs to set the default path and enable auto download. This is necessary to make my automation work. I use ChromeOptions.add_experimental_option("prefs", prefdictionary) with the dictionary containing the following valid settings {"download.default_directory": defaultdir, "download.prompt_for_download": False, "plugins.always_open_pdf_externally": True}. This works perfectly without UC. When using UC, it causes a crash when UC is calling the init-routine of the parent class i. e. the call super(Chrome, self).init(service=service, options=options, keep_alive=keep_alive,) in line 466 (version 3.54 of UC) causes the crash.

Moreover, when runnig UC without this pref, I get an error in line 843 / 793 respectively stating an WinError 6 with an invalid handle.

Please check and advise.

dornech avatar Dec 25 '23 23:12 dornech

I faced the same issue a few weeks ago. Here is how you can set the default download dir The key is to use ChromeOptions from undetected_chromedriver

from undetected_chromedriver.options import ChromeOptions
from undetected_chromedriver import Chrome

chrome_options = ChromeOptions()

prefs = {"download.default_directory" : default_download_path}
chrome_options.add_experimental_option("prefs", prefs)

 driver= Chrome(
    options = chrome_options,
    debug=debug,
)

pedro-peixot0 avatar Dec 26 '23 13:12 pedro-peixot0

Oh, thanks, great. It works. Caused some work because I want to integrate different wrappers as base in a versatile generator function but I think it worked.

dornech avatar Dec 26 '23 23:12 dornech