Skip to content

How to Bypass the Captcha on a Headless Linux Machine #3557

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
vinayyak opened this issue Feb 21, 2025 · 2 comments
Closed

How to Bypass the Captcha on a Headless Linux Machine #3557

vinayyak opened this issue Feb 21, 2025 · 2 comments
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@vinayyak
Copy link

vinayyak commented Feb 21, 2025

Hi, I am using a Headless Linux Server from Azure to bypass a captcha which requires me to click the cloudflare captcha box,

  • When I run with:
with SB(uc=True, headless=True, incognito=True) as sb:
    sb.driver.uc_open_with_reconnect(url, 10)

Then It cannot bypass the captcha page. I also cannot use: sb.uc_gui_click_captcha() since PyAutoGUI can't be used in headless mode.

  • If I try to use sb.uc_gui_click_captcha() by making headless False : SB(uc=True, headless=False, incognito=True) as sb:, I get:
start error

X11 display failed! Will use regular xvfb!
  • Even setting: SB(uc=True, headless=False, incognito=True, xvfb=True) as sb: results in the same X11 display failed error even though I have manually verified having it.

  • NOTE: Browser was installed via sudo apt install google-chrome-stable

What can I do to bypass this captcha on my headless linux machine? I have read multiple similar threads but was not able to fix this issue, any suggestions and examples would be appreciated!

@mdmintz mdmintz added question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Feb 21, 2025
@mdmintz
Copy link
Member

mdmintz commented Feb 21, 2025

https://github.com/mdmintz/undetected-testing/blob/master/raw_gitlab_uc.py is working for me in GitHub Actions:

https://github.com/mdmintz/undetected-testing/actions/runs/13463833326/job/37625081029

Image

That one ran this exact script:

from seleniumbase import SB

with SB(uc=True, test=True) as sb:
    url = "https://gitlab.com/users/sign_in"
    sb.uc_open_with_reconnect(url, 5)
    sb.uc_gui_click_captcha()
    sb.sleep(2)
    sb.uc_gui_handle_captcha()
    sb.assert_text("Username", '[for="user_login"]', timeout=3)
    sb.assert_element('label[for="user_login"]')
    sb.highlight('button:contains("Sign in")')
    sb.highlight('h1:contains("GitLab.com")')
    sb.post_message("SeleniumBase wasn't detected", duration=4)
    print("Success! Website did not detect SeleniumBase!")

Based on the debug messages, sb.uc_gui_click_captcha() succeeded, so sb.uc_gui_handle_captcha() wasn't needed.

Make sure your Linux machine has the required X11 dependencies. GitHub Actions Linux already has that by default.

See the YML files in https://github.com/mdmintz/undetected-testing/tree/master/.github/workflows for instructions on configuring your GitHub Actions scripts.

@mdmintz mdmintz closed this as completed Feb 21, 2025
@vinayyak
Copy link
Author

vinayyak commented Feb 21, 2025

Thankyou for the quick response and the test @mdmintz,

Was able to pass the captcha with with SB(uc=True, test=True) as sb: via sb.uc_gui_click_captcha() and sb.uc_gui_handle_captcha() after resolving X11 dependency issues in my local environment. Using a fresh server also helped to not get blocked right off the bat.

  • Attaching some steps that helped me fix the X11 conflicts for any future readers:
sudo apt-get update

sudo apt-get install -y xvfb x11-utils xorg xserver-xorg-core

sudo apt-get install -y x11-apps xfonts-base xfonts-75dpi xfonts-100dpi xfonts-cyrillic

pip install pyautogui

Useful Comment for X11 Issues made by @mdmintz earlier

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