Tuesday, 21 June 2022

Selenium XVFB - Unable to receive message from renderer

Overview:

Selenium scraper works perfectly in headless mode. Spawning a virtual display shows no errors via XVFB:

from xvfbwrapper import Xvfb

vdisplay = Xvfb()
vdisplay.start()
vdisplay.stop()

But when I try to run them together, it errors out with:

[ERROR] SessionNotCreatedException: Message: session not created from disconnected: Unable to receive message from renderer


Configuration:

Below is my complete Selenium and XVFB configuration:

from selenium import webdriver
from selenium_stealth import stealth
from xvfbwrapper import Xvfb

vdisplay = Xvfb()
vdisplay.start()
options = webdriver.ChromeOptions()
prefs = {"browser.downloads.dir": "//tmp//", "download.default_directory": "//tmp//", "directory_upgrade": True}
options.add_experimental_option("prefs", prefs)
options.binary_location = '/opt/chrome/chrome'
#options.add_argument('--headless') #toggled on and off when running with or without XVFB
options.add_argument('--no-sandbox')
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1280x1696")
options.add_argument("--single-process")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-dev-tools")
options.add_argument("--no-zygote")
options.set_capability('unhandledPromptBehavior', 'ignore')
options.add_argument("download.default_directory=/tmp")
driver = webdriver.Chrome("/opt/chromedriver",options=options)
stealth(driver,
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        fix_hairline=True,
        )
vdisplay.stop()
driver.close()

Why is it not connecting to the display? My guess is it has something to do with the '--headless' toggle?

Versions and Tools:

  • Selenium version 3.141.0
  • xvfbwrapper version 0.2.9
  • Docker is used to compile and push to AWS Lambda (no changes are made in docker file with or without XVFB)


from Selenium XVFB - Unable to receive message from renderer

No comments:

Post a Comment