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.99k stars 1.16k forks source link

you cannot reuse the ChromeOptions object #1342

Closed alimp5 closed 1 year ago

alimp5 commented 1 year ago

Greetings! at first, i would thank you dear Leon for this python library. i don't know how i can to reuse and run the user_data_directory of a created chrome profile multiple times in undetected-chromedriver !? when i want to reuse the created profile, i got error you cannot reuse the ChromeOptions object. but i don't see this problem in selenium or selenium-wire. how to fix this issue? what's the solution ?. but when i use undetected-chromedriver in selenium-wire, i see error below.

even i called the UC-Driver separately two times but failed: at line 50:

import seleniumwire.undetected_chromedriver as uc
self.driver = uc.Chrome(use_subprocess=True,  version_main=chrome_ver,  user_data_dir=self.user_data_dir,  
            options=self.chrome_options,  seleniumwire_options=sw_options)

at line 60 again:

self.driver.close()
self.driver.quit()
self.driver = uc.Chrome(use_subprocess=True,  version_main=chrome_ver,  user_data_dir=self.user_data_dir,  
                options=self.chrome_options,  seleniumwire_options=sw_options)

thanks a lot ;X

Error:

Internal Server Error: /admin/ea_app/bot/add/
Traceback (most recent call last):
  File "C:\ea_auto_snipe\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\ea_auto_snipe\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\django\contrib\admin\options.py", line 683, in
wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\django\utils\decorators.py", line 133, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\django\views\decorators\cache.py", line 62, in
_wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\django\contrib\admin\sites.py", line 242, in inner
    return view(request, *args, **kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\django\contrib\admin\options.py", line 1885, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
  File "C:\ea_auto_snipe\lib\site-packages\django\utils\decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\django\utils\decorators.py", line 133, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\django\contrib\admin\options.py", line 1745, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "C:\ea_auto_snipe\lib\site-packages\django\contrib\admin\options.py", line 1797, in _changeform_view
    self.save_model(request, new_object, form, not add)
  File "C:\ea_auto_snipe\lib\site-packages\django\utils\decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\ea_auto_snipe\ea_games\ea_app\admin.py", line 807, in save_model
    sel_result = SeleniumLogin().run_browser(bot_info)
  File "C:\ea_auto_snipe\ea_games\ea_app\all_utils\selenium_login_sw.py", line 181, in run_browser
    self.driver = uc.Chrome(use_subprocess=True,  version_main=chrome_ver,  user_data_dir=self.user_data_dir,  options=self.chrome_options,  seleniumwire_options=sw_options)
  File "C:\ea_auto_snipe\lib\site-packages\seleniumwire\undetected_chromedriver\webdriver.py", line 61, in __init__
    super().__init__(*args, **kwargs)
  File "C:\ea_auto_snipe\lib\site-packages\undetected_chromedriver\__init__.py", line 244, in __init__
    raise RuntimeError("you cannot reuse the ChromeOptions object")
RuntimeError: you cannot reuse the ChromeOptions object
lonewolf-github commented 1 year ago

This error was introduced to prevent people fron accidentally stacking options, as it simply adds new ones if you call it again. The solution I found was to make a ChromeOptions list and call the indexes according to which options i wanted used. However still, each launch must have their own options index

alimp5 commented 1 year ago

Hi @lonewolf-github i'm thankful if you share an example. note: my options are as below and i don't want to change them for every launch.

        self.chrome_options.add_argument("--no-first-run")
        self.chrome_options.add_argument("--no-service-autorun")
        self.chrome_options.add_argument("--password-store=basic")
        self.chrome_options.add_argument("--no-default-browser-check")
        self.chrome_options.add_argument("--window-size=1000,900")
        sw_options = {}
        if ":" in self.proxy_info:
            sw_options = { 
                'proxy': { 
                    'http':  rf'http://{self.proxy_info}',
                    'https': rf'https://{self.proxy_info}',
                } 
            } 

Thanks..

Edited: Oh yes...... you means i should to define a new line self.chrome_options = uc.ChromeOptions() like self.driver =uc.Chrome(.......) and then add my arguments? YES?

lonewolf-github commented 1 year ago

Try something like this:

options_list = []

#Launch 1
options[0] = uc.ChromeOptions()
options[0].add_argument("--user-data-dir=" + user_data_dir) 
driver1 = uc.Chrome(options=options[0])

#Launch 2
options[1] = uc.ChromeOptions()
options[1].add_argument("--user-data-dir=" + user_data_dir) 
driver2 = uc.Chrome(options=options[1])
sSuHao commented 1 year ago

Hi @lonewolf-github i'm thankful if you share an example. note: my options are as below and i don't want to change them for every launch.

        self.chrome_options.add_argument("--no-first-run")
        self.chrome_options.add_argument("--no-service-autorun")
        self.chrome_options.add_argument("--password-store=basic")
        self.chrome_options.add_argument("--no-default-browser-check")
        self.chrome_options.add_argument("--window-size=1000,900")
        sw_options = {}
        if ":" in self.proxy_info:
            sw_options = { 
                'proxy': { 
                    'http':  rf'http://{self.proxy_info}',
                    'https': rf'https://{self.proxy_info}',
                } 
            } 

Thanks..

Edited: Oh yes...... you means i should to define a new line self.chrome_options = uc.ChromeOptions() like self.driver =uc.Chrome(.......) and then add my arguments? YES?

Hi, I’m just curious that what’s the purpose of your chrome options? Does that help you hide selenium?

ITMEDIAVISION commented 4 months ago

This error was introduced to prevent people fron accidentally stacking options, as it simply adds new ones if you call it again. The solution I found was to make a ChromeOptions list and call the indexes according to which options i wanted used. However still, each launch must have their own options index

Would there be a way to bypass this? i got a script running that fetches links to perform a automated download once downloaded it shuts off the browser and then "repeats" the process

==UPDATE== i got rid of the options and after that it worked normally