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.53k stars 1.13k forks source link

Does it support opion 'enable_mobile' ? #865

Open jw-song opened 1 year ago

jw-song commented 1 year ago

I used the following options to use undetected chromedriver on Android. options = uc.ChromeOptions() options.enable_mobile('com.android.chrome') driver = uc.Chrome(version_main=106, options=options)

However, I got the following error:

Message: invalid argument: cannot parse capability: goog:chromeOptions from invalid argument: unrecognized chrome option: debuggerAddress

When I changed option.enable_mobile to options.add_experimental_option('androidPackage', 'com.android.chrome'), the result was same

kaliiiiiiiiii commented 1 year ago

you can use Selenium_Profiles still in progress//working on btw

George-Seven commented 1 year ago

@jw-song you need to comment out one line:-

Specifically:-

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

to

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

from undetected_chromedriver/__init__.py to make it work.

One-liner to do it:-

sed -i 's/options.debugger_address = "%s:%d" % (debug_host, debug_port)/# options.debugger_address = "%s:%d" % (debug_host, debug_port)/' "$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")/undetected_chromedriver/__init__.py"

This will make undetected-chromedriver work on Android device.

One-liner to undo it:-

sed -i -E 's/#.*options.debugger_address = "%s:%d" % \(debug_host, debug_port\)/options.debugger_address = "%s:%d" % \(debug_host, debug_port\)/' "$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")/undetected_chromedriver/__init__.py"
desis123 commented 1 year ago

Following code works for me

 set_device_metrics_override = dict({
              "width": 375,
              "height": 812,
              "deviceScaleFactor": 50,
              "mobile": True
          })
 browser = uc.Chrome(options=options) 
 browser.execute_cdp_cmd('Emulation.setDeviceMetricsOverride', set_device_metrics_override)   

For Different Mobile metrics you can adopt from following url , but instead of json you have set it as dict ,https://chromium.googlesource.com/chromium/src/+/167a7f5e03f8b9bd297d2663ec35affa0edd5076/third_party/WebKit/Source/devtools/front_end/emulated_devices/module.json