When using undetected-chromedriver I can't change the useragent

333 views Asked by At

Have anyone faced this issue before? here is my code

from selenium import webdriver
import time
import undetected_chromedriver as uc


# Define a custom user agent string
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"

# Set up Chrome WebDriver with the custom user agent
chrome_options = uc.ChromeOptions()
chrome_options.headless = False

chrome_options.add_argument(f"user-agent={user_agent}")

# Initialize the WebDriver with the specified options
driver = uc.Chrome(options=chrome_options)

# You can now use the driver with the custom user agent
driver.get("https://amiunique.org/fingerprint")
time.sleep(40)

I have tested this method without using undetected-chromedriver uc and the useragent changed, but for some reason when ever I use undetected-chromedriver the useragent refuses to change, any thoughts?

0

There are 0 answers