Open jw-song opened 1 year ago
you can use Selenium_Profiles still in progress//working on btw
@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"
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
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