SOLVED; Chromium Webdriver with "–no-sandbox" is opening a fully transparent/invisible Chrome window

Question:

The relevant code is as follows:

    # find the Chromium profile with website caches for the webdriver
    chrome_options = Options()
    profile_filepath = "user-data-dir=" + "/home/hephaestus/.config/chromium/Profile1"
    chrome_options.add_argument(str(profile_filepath))
    
    # put chromium into --no-sandbox mode as a workaround for "DevToolsActivePort file doesn't exist"
    chrome_options.add_argument("--no-sandbox")
    
    # start an automatic Chrome tab and go to embervision.live; wait for page to load
    driver = webdriver.Chrome("./chromedriver", options=chrome_options)

`

When I run this Python code (and import the needed libraries), I get the screenshot below. Chromium that was opened with the above code is on the right, and is transparent and glitching out.

Desktop view with Chromium webdriver tab glitching out on the right

I am able to enter web addresses and interact with the page, but I just can’t see any of it. I’m not sure why.

I deleted and re-downloaded Selenium and Chromium, to no avail. I had to add the "–no-sandbox" option because it was getting another error that said "DevToolsActivePort file doesn’t exist".

I’m not sure what else is causing this issue. Any help is appreciated. Thank you!

Asked By: Jordan Johnston

||

Answers:

So I found a solution that works for me!

  1. Uninstall and reinstall Chromium completely. When reinstalling, check that your Chromium version matches with Selenium (which I didn’t even know was a thing).

  2. DO NOT run your Python code as a sudo user. I did "sudo python3 upload_image.py" and got the "DevToolsActivePort file doesn’t exist" error. When I ran just "python3 upload_image.py", it did not raise the error.

  3. Do not use the option "–no-sandbox" when running as a non-sudo user ("python 3 upload_image.py"). For some reason, the "–no-sandbox" option also broke my Chromium browser in the same transparent/infinite way as I posted above.

Hope this helps someone in the future!

Answered By: Jordan Johnston