So Im trying to modify the user agent of the chrome driven by undetected chrome to pretend I am a mobile user. it works with usual chrome driver but not the undetected one, I don't sure what I have to change to make it work for undetected chrome, here is the code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
import undetected_chromedriver.v2 as uc
options = uc.ChromeOptions()
options.add_argument(
"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36")
# s = Service('./chromedriver')
# driver = webdriver.Chrome(options=options, service=s)
driver = uc.Chrome(options=options)
driver.get('https://www.google.com')
print(driver.execute_script("return navigator.userAgent;"))
time.sleep(1000000)
So if use the undetected chrome, the user agent printed is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
but it is working if i use the regular chrome driver
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36