Fix user-agent string in headless UC Mode

This commit is contained in:
Michael Mintz 2024-02-20 15:56:37 -05:00
parent 6b1c9931bd
commit 044fc46eba
1 changed files with 15 additions and 1 deletions

View File

@ -3460,7 +3460,21 @@ def get_local_driver(
try:
user_agent = driver.execute_script(
"return navigator.userAgent;"
).replace("Headless", "")
)
if (
major_chrome_version
and full_ch_version
and full_ch_version.count(".") == 3
and full_ch_version in user_agent
):
mcv = major_chrome_version
user_agent = user_agent.replace(
"Chrome/%s" % full_ch_version,
"Chrome/%s.0.0.0" % mcv
)
user_agent = user_agent.replace(
"Headless", ""
)
chrome_options.add_argument(
"--user-agent=%s" % user_agent
)