Skip to content

Selenium Headless Browser Detection on Brotector Test Site #3758

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

Closed
alpgul opened this issue May 20, 2025 · 3 comments
Closed

Selenium Headless Browser Detection on Brotector Test Site #3758

alpgul opened this issue May 20, 2025 · 3 comments
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@alpgul
Copy link

alpgul commented May 20, 2025

Problem Overview

When attempting to access "https://kaliiiiiiiiii.github.io/brotector/?crash=false" using SeleniumBase with headless mode and various anti-detection settings, the website successfully detects:

  • Headless browser
  • User-agent override

Reproduction Steps

  1. Use SeleniumBase with the following configuration:

    • Headless mode enabled
    • Undetected Chrome mode (uc=True)
    • Test mode
    • Maximize window
    • Incognito mode
    • Do not track enabled
    • Ad block enabled
  2. Code used for testing:

from seleniumbase import SB

with SB(uc=True, headless2=True, test=True, maximize=True, incognito=True, do_not_track=True, ad_block=True) as sb:
    url = "https://kaliiiiiiiiii.github.io/brotector/?crash=false"
    sb.activate_cdp_mode(url)
    sb.cdp.flash("Test Results")
    sb.sleep(0.5)
    sb.cdp.save_screenshot("bscan.png")
@mdmintz mdmintz added question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels May 20, 2025
@mdmintz
Copy link
Member

mdmintz commented May 20, 2025

This is all you need:

from seleniumbase import SB

with SB(uc=True, test=True) as sb:
    url = "https://kaliiiiiiiiii.github.io/brotector/?crash=false"
    sb.activate_cdp_mode(url)
    sb.cdp.gui_click_element("button")
    sb.sleep(2)

Note that you don't need headless mode on Linux because there's xvfb=True, which lets you run regular Chrome on a machine that has no display. And you can use PyAutoGUI actions too.

@mdmintz mdmintz closed this as completed May 20, 2025
@alpgul
Copy link
Author

alpgul commented May 20, 2025

Is there no way to prevent user agent detection in headless mode? I'm testing on windows

@mdmintz
Copy link
Member

mdmintz commented May 20, 2025

If you don't want to see the browser, you can move the window position off-screen:
sb.set_window_position(5000, 5000)

Eg.

from seleniumbase import SB

with SB(uc=True, test=True) as sb:
    sb.set_window_position(5000, 5000)
    url = "https://kaliiiiiiiiii.github.io/brotector/?crash=false"
    sb.activate_cdp_mode(url)
    sb.sleep(2)

Although note that if you want to perform PyAutoGUI actions, the window must be visible and on-screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants