-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NODRIVER] Bot detected in headless mode by user agent #2003
Comments
Just override the user agent before open the page. await tab.send(cdp.network.set_user_agent_override(
user_agent=browser.info.get("User-Agent").replace("Headless", "")
)) |
Yes, but this would be at the tab level and I would like it to be at the browser level like with undetected_chromedriver, that is, if I open new tabs, the user agent would already be patched. |
Use your own user agent as browser arg |
Remove the "Headless" from de user agent has worked for me very well, to make it at browser level I added this line: driver = selenium.webdriver.chrome.webdriver.WebDriver(options=driver_opts)
current_user_agent = driver.execute_script("return navigator.userAgent;")
driver.execute_cdp_cmd(
'Network.setUserAgentOverride',
{
"userAgent": current_user_agent.replace('Headless', ''),
},
) It worked doing int like this rather than adding the user agent argument driver_opts.add_argument('--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36') |
nodriver is easily detectable in headless mode because the user agent is not patched:
How to fix this without setting a specific user agent in
browser_args
?Also, I would like to know if there is any equivalent method to
execute_script()
The text was updated successfully, but these errors were encountered: