sbvirtualdisplay (current version 1.4.0) is a Python library that provides a customized virtual display for headless browser automation, primarily designed for use with SeleniumBase. It functions as a wrapper around Xvfb, Xephyr, or Xvnc programs, enabling browser tests to run in environments without a physical display server, which is particularly useful for Linux backend servers. The library is actively maintained with a steady release cadence.
pip install sbvirtualdisplayVerified import paths — ran on the pinned version, not inferred.
Initialize a virtual display with specified visibility and resolution, then execute browser automation code within its context. The context manager ensures the display is properly started and stopped.
Upgrade to Python 3.8 or newer, or pin sbvirtualdisplay to <1.4.0 if Python 3.7 is required.
Upgrade to Python 3.8 or newer. If older Python versions are necessary, use sbvirtualdisplay <1.3.0.
Ensure that a compatible X server (like Xvfb) is installed and available on the Linux system where sbvirtualdisplay is used. For macOS/Windows, consider native headless browser modes (e.g., Chrome/Firefox `--headless=new`) or other platform-specific solutions.
Install `Xvfb` (or `Xephyr`/`Xvnc`) via your system's package manager (e.g., `sudo apt-get install xvfb` on Ubuntu) before using `sbvirtualdisplay`.
Install Xvfb using your system's package manager. For Debian/Ubuntu: `sudo apt-get install xvfb`. For CentOS/RHEL: `sudo yum install xorg-x11-server-Xvfb`.
Ensure all previous virtual display processes are terminated. If manually specifying `os_display_number`, try removing it to let sbvirtualdisplay find a free display, or choose a higher, unused number (e.g., `display = Display(visible=0, os_display_number=100)`).
Use one of the supported backend names: `'xvfb'`, `'xephyr'`, or `'xvnc'`. For example, `Display(backend='xvfb', ...)`. Ensure the chosen backend's executable is also installed on your system.