Fix Transparent Chrome Windows in Chromedriver No-Sandbox
In this article
When you run Chromedriver with the --no-sandbox flag (common in Docker or CI environments), Chrome windows can render as fully transparent or invisible. This happens because the no-sandbox mode disables GPU compositing and hardware acceleration, which some Linux systems need to draw the browser window properly. The fix is to force Chrome to use software rendering and disable GPU-related features that cause the transparency glitch. Below is a step-by-step guide to resolve this issue quickly.
What You'll Need
- Access to the code where you launch Chromedriver (Python, Java, Node.js, etc.)
- Ability to edit Chrome options/capabilities in your test script
- A terminal or command line to test Chrome flags manually (optional but helpful)
Step-by-Step
- Identify where you set the no-sandbox flag. Look for
--no-sandboxin your Chromedriver options. It is usually added as a ChromeOption or capability. Keep it there for now—you need it for running in restricted environments. - Add the
--disable-gpuflag. This tells Chrome not to use the GPU for rendering. In Python (Selenium), it looks like:options.add_argument('--disable-gpu')
In Java:options.addArguments("--disable-gpu");In Node.js:options.addArguments('--disable-gpu'); - Add the
--disable-software-rasterizerflag. This prevents Chrome from falling back to a software rasterizer that can also cause transparency. Add it the same way as above. - Add
--disable-dev-shm-usageif you are in a container. This avoids shared memory issues that can also cause rendering problems. It is especially common in Docker. - Set the window size explicitly. Sometimes an undefined window size leads to a zero-sized transparent window. Add
--window-size=1920,1080(or any size you need). - Disable the GPU sandbox specifically. Add
--disable-gpu-sandboxto prevent GPU-related sandboxing that may conflict with no-sandbox mode. - Force software rendering via
--use-gl=swiftshader. This makes Chrome use SwiftShader, a software renderer, for WebGL and compositing. This is often the decisive fix. - Add
--disable-extensionsand--disable-background-networking. These are not strictly necessary but reduce background processes that could interfere with rendering. - Apply the flags in your code. Make sure all flags are added before starting the WebDriver session. Example in Python:
options = webdriver.ChromeOptions() options.add_argument('--no-sandbox') options.add_argument('--disable-gpu') options.add_argument('--disable-software-rasterizer') options.add_argument('--disable-dev-shm-usage') options.add_argument('--window-size=1920,1080') options.add_argument('--disable-gpu-sandbox') options.add_argument('--use-gl=swiftshader') options.add_argument('--disable-extensions') options.add_argument('--disable-background-networking') driver = webdriver.Chrome(options=options) - Test your script. Run it and take a screenshot to verify the window is visible. If it still appears transparent, proceed to the Troubleshooting section.
Common Mistakes
- Forgetting to add the flags to the same options object. If you create a new options object later, the flags won't apply.
- Using
--disable-gpualone without--use-gl=swiftshader. On some systems, disabling the GPU without providing a software fallback still results in transparency. - Setting the window size after the driver starts. The window size must be set as a flag before initialization; using
driver.set_window_size()later may not fix the rendering issue. - Assuming the issue is with your code. It is almost always a Chrome flag issue, not a bug in your test logic.
Tips
- Use a headless browser if you don't need to see the window. Headless mode (
--headless) avoids the transparency problem entirely and is faster for CI. - Test the flags manually in a terminal. Run
google-chrome --no-sandbox --disable-gpu --use-gl=swiftshader about:blankto see if the window appears correctly before modifying your code. - Keep a consistent set of flags across all environments. If your tests run locally and in Docker, use the same flags everywhere to avoid environment-specific surprises.
- Update Chrome and Chromedriver to the latest versions. Older versions have more rendering bugs that are fixed in newer releases.
Troubleshooting
- Window is still transparent after adding all flags. Try adding
--disable-accelerated-2d-canvasand--disable-accelerated-video-decode. These further disable hardware acceleration. - Chrome crashes or does not start. Remove
--use-gl=swiftshaderand instead try--use-gl=anglewith--use-angle=swiftshader. This is an alternative software rendering path. - Only some elements are transparent. This may be a WebGL issue. Add
--enable-webgland--ignore-gpu-blocklistto force WebGL to work in software mode. - Works locally but not in Docker. Ensure you have the necessary system libraries installed (like
libgl1andlibglib2.0-0). Also, try adding--disable-dev-shm-usageand increasing shared memory with--shm-size=2gin your Docker run command. - Screen captures are black even though the window looks fine. This is a separate issue with the screenshot mechanism. Try using
--hide-scrollbarsand ensure the window is in the foreground.
Frequently Asked Questions
Why does the no-sandbox flag cause transparency?
No-sandbox disables Chrome's security sandbox, which also disables the GPU process isolation. Without that isolation, Chrome often falls back to a broken GPU path that results in no rendering output (transparent window).
Can I just remove the no-sandbox flag?
Yes, if you are running as root or in a restricted environment where sandboxing works, removing it will likely fix transparency. But if you need no-sandbox for container compatibility, use the flags above.
Does this fix work on Windows or macOS?
Transparency is mostly a Linux issue. On Windows and macOS, the no-sandbox flag rarely causes transparency, but adding --disable-gpu is harmless.
Will these flags slow down my tests?
Software rendering is slower than GPU rendering, so page load and animations may be slightly slower. But for most automation, the difference is negligible.
Is there a way to keep GPU acceleration and still avoid transparency?
You can try --disable-gpu-sandbox alone without --disable-gpu. Some users report that this keeps GPU acceleration while fixing transparency, but it is less reliable.
What if I use Firefox or another browser?
This guide is specific to Chrome/Chromium. Firefox has its own flags (like MOZ_HEADLESS or --headless) and does not have the same transparency issue.