As pointed out by Moshe, there is no direct equivalent of Xvfb
on Windows.
But you can simulate it's functionality by using a virtual display.
One option i've found is the Virtual Display Driver available on GitHub here.
After installation, this driver creates a virtual second screen and you can utilize the argument --window-position
to position Chrome on this virtual display, effectively keeping it off the main screen.
# Calculate the window position for the virtual display
# based on yout requirements
x = ... # window's X position
y = ... # window's Y position
options = ChromeOptions()
options.add_argument(f"--window-position={x},{y}")
options.add_argument("--start-maximized")
You can also hide it from the taskbar by installing the pygetwindow
package:
import pygetwindow
chrome_window_title = "<expected Chrome's window title>"
chrome_window = pygetwindow.getWindowsWithTitle(chrome_window_title)[0]
chrome_window.hide()
Although it is a bit cumbersome, I found this method works nicely even when the --headless
argument is detected and the scraper is rejected