You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_inrange(12):
withSB(uc=True, headed=True, browser="chrome", xvfb=False) assb:
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_inrange(12):
withSB(uc=True, headed=True, browser="chrome", xvfb=False) assb:
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!
The text was updated successfully, but these errors were encountered:
I see the issue.
CDP Mode activates the virtual display by default on Linux after the first browser has been launched.
(Whenever the virtual display is running, any new browser window will launch inside there, invisible.)
I can fix this in SB() by passing additional parameters into start() from browser_launcher.py:
Since the browser has already been launched by the time the start() method is called, I only need to pass parameters related to determining whether or not Xvfb needs to be activated.
I also want to add, that the Xvfb processes do not exit automatically but keep accumulating in the background. As a quick and dirty workaround I am using subprocess.run(["killall", "Xvfb"], check=True) but of course that is not ideal.
Thanks for your work and the quick reply, I hope that helps!
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
andxvfb=False
. My goal is to see the browser automation happening during each iteration of a loop. Below is the structure of my code: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:
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!
The text was updated successfully, but these errors were encountered: