Fix Puppeteer Chrome Errors on Render Deploy
In this article
When you deploy a Puppeteer app to Render, you often hit errors like Chrome failed to start, Missing X server or $DISPLAY, or Failed to launch the browser process. This guide walks you through the exact fixes—covering missing system libraries, sandbox issues, and correct build commands—so your headless browser runs smoothly on Render's free and paid instances.
What You'll Need
- A Render account with a deployed Node.js service (or a new one you're about to create).
- Access to your project's repository (GitHub, GitLab, or Bitbucket) to edit code and push changes.
- Basic familiarity with the command line and your
package.jsonfile. - Puppeteer installed in your project (if not, run
npm install puppeteerlocally).
Step-by-Step
- Check your Puppeteer version. Older versions (pre-19) often have different dependency needs. Run
npm list puppeteerlocally. If you're on a version below 19, update to the latest withnpm install puppeteer@latest. This ensures you get the latest Chromium build and fixes. - Install system dependencies on Render. Render's default Node environment lacks many libraries Chrome needs. In your Render dashboard, go to your service's Environment tab and add a build command. Under Build Command, replace it with:
apt-get update && apt-get install -y libnss3 libatk-bridge2.0-0 libdrm2 libxkbcommon0 libgbm1 libasound2 && npm install
This installs the essential shared libraries for Chromium. If you're using a Dockerfile, add those packages there instead. - Set the correct launch arguments. In your Puppeteer code, you must disable the sandbox and set a few flags. Update your launch call to:
const browser = await puppeteer.launch({ headless: 'new', args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-gpu' ] });The--no-sandboxflag is critical because Render runs containers as root, and Chrome's sandbox fails without proper kernel support.--disable-dev-shm-usageprevents crashes from limited shared memory. - Ensure Puppeteer's cache is available. On Render, the home directory is not persistent, but the build cache is. To avoid re-downloading Chromium on every deploy, set the cache directory in your build command. Modify the build command to:
apt-get update && apt-get install -y libnss3 libatk-bridge2.0-0 libdrm2 libxkbcommon0 libgbm1 libasound2 && npm install && npx puppeteer browsers install chrome
This ensures Chromium is installed during the build phase, and Render caches it. Also, set the environment variablePUPPETEER_CACHE_DIRto/opt/render/.cache/puppeteerin your service's environment. - Use the correct headless mode. If you're using Puppeteer v22 or later, the old
headless: trueis deprecated. Useheadless: 'new'or simplyheadless: true(which now defaults to the new mode). If you see errors aboutheadlessbeing invalid, update your code accordingly. - Handle the “Missing X server” error. This happens when Chrome tries to launch in non-headless mode. Ensure you always pass
headless: true(or'new') in production. If you have conditional logic, force headless whenprocess.env.NODE_ENV === 'production'. - Test locally with the same flags. Before pushing, run your script locally with the same
--no-sandboxargs to verify it works. This saves you from multiple deploy cycles. - Deploy and check logs. Push your changes to your repository. Render will automatically redeploy. Go to the Logs tab in your Render dashboard and look for any Chrome-related errors. If you see a missing library, add it to the apt-get install list in step 2.
Common Mistakes
- Forgetting the build command override. Many users keep the default
npm installand wonder why Chrome fails. The apt-get step is essential. - Using
--no-sandboxonly in development. Some put it in an if-statement for production, but forget to setNODE_ENVon Render. Always set it unconditionally or ensure the environment variable is set. - Not updating Puppeteer. Old versions may not support the latest Chromium or may have bugs fixed in later releases.
- Ignoring the cache directory. Without it, Render downloads Chromium on every deploy, which can cause timeouts and flaky builds.
Tips
- Use a Dockerfile for full control. If you're comfortable with Docker, you can base your image on
node:20-slimand install the libraries in the Dockerfile. This makes the setup reproducible and avoids build command hacks. - Set memory limits. Render's free tier has limited memory. If you're scraping heavy pages, add
--max-old-space-size=512to your Node start command, or use--disable-dev-shm-usageto reduce memory pressure. - Use environment variables for flags. Instead of hardcoding, read a
PUPPETEER_ARGSenv var to make it easier to tweak without code changes. - Monitor your logs. Render logs show the exact error. Copy the error message and search for it—most are known and have fixes.
Troubleshooting
If you still get errors, follow these steps:
- Read the full error message. It often says which library is missing, e.g.,
error while loading shared libraries: libX11.so.6. Add that library to your apt-get install list. - Check Chrome's stderr. In your Puppeteer launch, add
dumpio: truetemporarily to see Chrome's output in your logs. This reveals what's failing. - Try a different Chromium version. If the latest fails, you can pin a specific version by setting
PUPPETEER_CHROMIUM_REVISIONto an older revision. But first try the latest. - Verify your build command actually ran. In Render, check the build logs. If the apt-get command failed due to network issues, it might be skipped. Run it manually in a local Docker container to test.
- Use a minimal test script. Create a simple
test.jsthat just launches Chrome and prints 'OK'. Deploy that to isolate whether the issue is in your code or the environment.
Frequently Asked Questions
Why do I get “Failed to launch the browser process” on Render but not locally?
Render's container lacks system libraries that Chrome needs. The apt-get install command in the build step resolves this.
Do I need to use --no-sandbox?
Yes, on Render, because the container runs as root and Chrome's sandbox cannot function without proper kernel privileges. It's safe for headless scraping.
How do I keep Chromium from downloading on every deploy?
Set the PUPPETEER_CACHE_DIR environment variable to a persistent directory like /opt/render/.cache/puppeteer and run npx puppeteer browsers install chrome in the build command.
Can I use puppeteer-core instead?
Yes, but then you must install a browser separately (e.g., via a build step). Puppeteer-core doesn't download Chrome, so you need to manage the binary yourself.
Why is my Puppeteer script timing out on Render?
This is often due to insufficient memory or CPU on the free tier. Try simplifying your script, using --disable-dev-shm-usage, or upgrading to a paid instance.
What if I see “Missing X server or $DISPLAY”?
That means Chrome tried to launch in headed mode. Ensure you pass headless: true (or 'new') in your launch options, especially in production.