Chrome headless mode triggers WhatsApp Web update prompt despite correct version

I built a Python Selenium bot that works great in normal browser mode across Firefox, Chrome, and Brave. However, when I switch to headless mode, I run into a weird issue. Firefox works fine headless, but Chrome and Brave keep showing me an “update your browser” message on WhatsApp Web.

The strange part is that Chrome, Brave, and my WebDriver are all running version 98.xxx - they’re perfectly up to date. This only happens in headless mode, not when the browser window is visible.

I captured a screenshot using driver.save_screenshot() and confirmed that WhatsApp Web is definitely showing the update prompt. Has anyone else encountered this problem? Why would WhatsApp Web think my browser needs updating only when running headless?

i had the same issue! turns out whatsapp web checks the user agent diff when in headless mode. try adding the --user-agent flag with a regular chrome ua string in your webdriver options. it fixed it for me super quick!

WhatsApp Web checks way more than just your user agent. Chrome’s headless mode changes tons of browser properties that WhatsApp can easily spot. Things like navigator.plugins, navigator.languages, and screen size all give you away, even if you’ve spoofed the user agent perfectly. I’ve had good luck adding these Chrome flags: --disable-blink-features=AutomationControlled and --disable-web-security. Also set --window-size=1920,1080 since headless defaults to weird dimensions that WhatsApp flags immediately. Another trick - inject JavaScript right after page load to change navigator.webdriver from true to false. Most sites check this property specifically to catch automated browsers.

The Problem:

You’re building a Python Selenium bot for WhatsApp Web, and it works fine in normal browser mode but fails in headless mode, displaying an “update your browser” message even though your browser (Chrome or Brave) and WebDriver are up-to-date. This suggests WhatsApp Web is detecting your browser as being automated or headless.

:thinking: Understanding the “Why” (The Root Cause):

WhatsApp Web employs techniques to detect and block automated bots. While simply updating your browser might sometimes resolve this, headless mode inherently modifies several browser properties that reveal its automated nature. These properties, which are usually hidden when the browser is visible, are checked by WhatsApp Web’s anti-automation measures. This includes user agent strings, JavaScript properties, and even plugin information. Simply changing the user agent might not be enough.

:gear: Step-by-Step Guide:

This guide focuses on mitigating WhatsApp Web’s detection mechanisms within your Selenium script using a multi-pronged approach. The key is to make your headless browser appear more like a genuine user’s browser.

Step 1: Spoof the User Agent and Key Browser Properties:
Modify your Selenium code to set a realistic user agent and adjust properties that reveal headless behavior. Below is an example using Chrome:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless=new") # Enable headless mode
options.add_argument("--window-size=1920,1080") # Set a realistic window size
options.add_argument("--user-agent=YOUR_USER_AGENT_STRING") # Replace with a real Chrome user agent string
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--disable-web-security") #Potentially allow access to more resources. Be cautious.

driver = webdriver.Chrome(options=options)

#Further actions are optional and may be unnecessary depending on WhatsApp's updates
#Inject Javascript to modify 'navigator.webdriver'
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

Step 2: Verify User Agent and other browser properties (optional):

After launching the browser, verify that your user agent and other browser properties appear to be normal. There are various methods to do this using Selenium:

user_agent = driver.execute_script("return navigator.userAgent;")
print(f"Current User Agent: {user_agent}")

webdriver_property = driver.execute_script("return navigator.webdriver;")
print(f"navigator.webdriver: {webdriver_property}")

Ensure your YOUR_USER_AGENT_STRING is a valid and recent Chrome user agent string. You can find updated strings online.

:mag: Common Pitfalls & What to Check Next:

  • Stale User Agent: Regularly update your user-agent string. WhatsApp frequently updates its detection methods.
  • Insufficient Masking: Even with these steps, WhatsApp might still detect your bot. Consider using more sophisticated anti-detection techniques if this is the case, or explore alternative automation platforms that handle this automatically.
  • Overly Aggressive Anti-Detection: Be cautious with methods like --disable-web-security. While helpful in some circumstances, it can trigger security warnings or make your bot vulnerable.
  • WhatsApp Updates: WhatsApp frequently updates its detection mechanisms. If the issue persists after these changes, check for any recent updates to WhatsApp Web.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.