Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Don't bypass cloudflare captcha with xvfb=True #3664

Answered by mdmintz
SergeyShilenkov asked this question in Q&A
Discussion options

Hi everyone!
Scrapper is running on my local machine with ubuntu 22.04. Works well in headed mode and bypass by Cloudflare captcha with cdp + PyAutoGUI but don't with xvfb
Screenshot from 2025年04月09日 23-16-24
Screenshot from 2025年04月09日 23-20-13

Here is the code that works:

with SB(
 uc=True, incognito=True, locale="en",
 window_position="0,0",
 window_size="1920,1080",
 headed=True,
) as sb:
sb.activate_cdp_mode(URL)
...
sb.cdp.gui_click_element('#turnstile-captcha div')
...

However, i need to run this on a linux server without gui so i go with (tried 3 options on my local machine with ubuntu 22.04 for test):

with SB(
 uc=True, incognito=True, locale="en",
 xvfb=True,
 xvfb_metrics="1920,1080",
) as sb:
sb.activate_cdp_mode(URL)
...
sb.cdp.gui_click_element('#turnstile-captcha div')
# sb.uc_gui_click_x_y(871, 718)
# sb.cdp.gui_click_x_y(871, 718)
sb.sleep(2)
sb.cdp.save_screenshot("1.png", "_dbg"))

In that case, nothing happens (captcha doesn't bypass, there are no errors in terminal).
There is another thing i don't understand is xvfb_metrics="1920,1080" but screenshots are 1280x701. Did I not configure xvfb correctly or not enough or what other possible reason for not passing the captcha in xvfb "mode"?

You must be logged in to vote

Cloudflare-bypass is working normally for me from GitHub Actions using Ubuntu Linux:

Note that Docker leaves a detectable fingerprint, and that many Linux servers (such as AWS) have a non-residential IP address range, which makes automation detectable.

Replies: 1 comment 3 replies

Comment options

Cloudflare-bypass is working normally for me from GitHub Actions using Ubuntu Linux:

Note that Docker leaves a detectable fingerprint, and that many Linux servers (such as AWS) have a non-residential IP address range, which makes automation detectable.

You must be logged in to vote
3 replies
Comment options

Thank you for response. But what about xvfb

 with SB(
 uc=True,
 incognito=True,
 locale="en",
 xvfb=True,
 xvfb_metrics="1920,1080",
 ) as sb:
 sb.set_window_size(1920, 1080)
 sb.activate_cdp_mode(URL)
 sb.cdp.gui_click_x_y(1400, 800)

and i get error

Exception: PyAutoGUI cannot click on point (1400, 800) outside screen. (Width: 1366, Height: 768)

Why i set up 1920x1080 but virtual screen is 1366x768?

PyAutoGUI==0.9.54
seleniumbase==4.36.1

Comment options

Might be something related to your environment. I'm not seeing that when running in GitHub Actions. Also, be sure you're using the latest version of SeleniumBase (Currently 4.37.1)

Comment options

upgrade SeleniumBase to 4.37.2. Tried the same code:

with SB(
 uc=True,
 incognito=True,
 locale="en",
 xvfb=True,
 xvfb_metrics="1920,1080",
) as sb:
 sb.set_window_size(1920, 1080)
 sb.activate_cdp_mode(URL)
 sb.cdp.gui_click_x_y(1400, 800)

got the same error:

Exception: PyAutoGUI cannot click on point (1400, 800) outside screen. (Width: 1366, Height: 768)

After some debugging I found that in activate_cdp_mode(url) an additional virtual screen is created right here. I'm not sure what the idea is here and if it's a bug, but after I commented out this line, my code worked

__activate_virtual_display_as_needed(headless, headed, xvfb, xvfb_metrics)

also without passed xvfb_metrics here:
driver.cdp_base = loop.run_until_complete(
cdp_util.start(
host=cdp_host,
port=cdp_port,
headless=headless,
headed=headed,
xvfb=xvfb,
)
)
Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /