Description
I am using the latest version of sb (v4.33.12), Python 3.13.1 on Linux Fedora 41 (Wayland, I did install xorg-x11-server-Xvfb) and I am encountering an issue while using SeleniumBase in CDP mode with headed=True
and xvfb=False
. My goal is to see the browser automation happening during each iteration of a loop. Below is the structure of my code:
for _ in range(12):
with SB(uc=True, headed=True, browser="chrome", xvfb=False) as sb:
sb.activate_cdp_mode("https://example.com")
# do stuff
In the first iteration, everything works perfectly:
The browser opens visibly (not in a virtual display).
It navigates to the website and performs the actions as expected.
Upon exiting the context manager, the browser process terminates correctly (confirmed via htop).
However, starting from the second iteration, the behavior changes:
The browser runs in the xvfb virtual display instead of being visible, despite headed=True and xvfb=False being explicitly set.
To verify this, I added a print(sb.xvfb) statement immediately after entering the context manager, which consistently outputs False.
This behavior does not change even when using "Driver" instead of "SB".
Interestingly, the issue does resolve when I avoid using CDP mode and use uc_open_with_reconnect and sb.click() or sb.uc_click() instead of sb.cdp.click() instead:
for _ in range(12):
with SB(uc=True, headed=True, browser="chrome", xvfb=False) as sb:
sb.uc_open_with_reconnect("https://example.com")
# do stuff
In this case, the browser remains visible on every iteration, and xvfb is correctly not used.
It seems there is something related to cdp not torn down correctly as using a normal sb.open() before the sb.activate_cdp_mode does not change anything about Chrome starting up in the xvfb display after the first iteration.
Just to clarify, I am not multithreading this script, issues related to this can be excluded.
Let me know if you need more details!