User Agents

Fix Puppeteer Browser Not Downloaded Error on Linux

The "browser is not downloaded" error in Puppeteer occurs when the library cannot find a compatible version of Chromium or Chrome in the expected cache directory. This usually happens during a failed installation, when using a package manager that skips post-install scripts, or when running in a restricted environment like Docker. To fix this, you must manually trigger the browser download or point Puppeteer to an existing system-installed browser.

What You'll Need

  • A Linux distribution (Ubuntu, Debian, CentOS, etc.)
  • Node.js and npm installed on your system
  • Sudo or root privileges to install system dependencies
  • An active internet connection to download the browser binaries

Step-by-Step

  1. Clear the Puppeteer Cache: Sometimes a corrupted download prevents Puppeteer from recognizing the browser. Start by removing the existing cache folder. Depending on your version, this is usually located in ~/.cache/puppeteer. Run rm -rf ~/.cache/puppeteer to ensure a clean slate.
  2. Force Re-installation of Puppeteer: Use npm to reinstall the package, which should trigger the postinstall script that downloads Chromium. Run npm install puppeteer. If you are using yarn, use yarn add puppeteer.
  3. Manually Trigger the Download: If the automatic install fails, Puppeteer provides a command-line tool to fetch the browser. Run the following command in your terminal: npx puppeteer browsers install chrome. This explicitly tells the Puppeteer CLI to download the latest compatible version of Chrome.
  4. Install Missing Linux System Dependencies: Even if the browser is downloaded, it will fail to launch if Linux is missing required shared libraries (like libX11 or libnss3). Run the following command on Ubuntu/Debian to install all necessary dependencies:
    sudo apt-get update && sudo apt-get install -y ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcbrotli0 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils
  5. Configure an External Browser Path: If you prefer to use a browser already installed on your system (like Google Chrome or Chromium), you can bypass the download entirely. Find the path to your browser executable (usually /usr/bin/google-chrome) and modify your Puppeteer launch configuration:
    const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome' });
  6. Verify the Installation: Create a small test script to ensure the error is gone. Run a script that launches the browser and closes it immediately:
    const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); await browser.close(); console.log('Success!'); })();

Common Mistakes

  • Using puppeteer-core instead of puppeteer: The puppeteer-core package does not download a browser by design. If you installed puppeteer-core, you must provide an executablePath or use a separate download tool.
  • Running as Root without Sandbox Flags: On many Linux distributions, Chrome cannot run as the root user unless the --no-sandbox flag is passed in the launch options.
  • Ignoring Post-install Errors: Many users overlook warnings during npm install that indicate the browser download failed due to network timeouts or permission issues.
  • Incorrect Cache Permissions: If the user running the Node.js process doesn't have write access to the ~/.cache directory, the browser will never be saved.

Tips

  • Use a .puppeteerrc.cjs file: You can create a configuration file in your project root to specify exactly where the browser should be downloaded, which is helpful for CI/CD pipelines.
  • Environment Variables: Use PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true if you are in a Docker environment where you intend to install the browser via the system package manager to keep image sizes small.
  • Version Matching: Always ensure your Puppeteer version matches the version of the browser you are manually pointing to; otherwise, you may encounter API mismatches.

Troubleshooting

If you still see the "browser is not downloaded" error after following the steps above, check the following:

  • Check Proxy Settings: If you are behind a corporate firewall, the browser download may be blocked. Set the HTTPS_PROXY environment variable before running the install command.
  • Disk Space: Chromium is a large binary. Ensure you have at least 500MB of free space in your home directory.
  • Docker Specifics: If this is happening inside a Docker container, ensure your Dockerfile includes the system dependency installation list mentioned in Step 4 and that you are not using a "slim" image that lacks basic C libraries.
  • Permissions: Try running chmod -R 755 ~/.cache/puppeteer to ensure the application can read the downloaded binaries.

Frequently Asked Questions

Why does Puppeteer not download the browser automatically?

This usually happens if the postinstall script is skipped by your package manager or if a network error occurred during the initial installation process.

Can I use Firefox instead of Chromium?

Yes, Puppeteer supports Firefox. You can install it using npx puppeteer browsers install firefox and then specify browser: 'firefox' in the launch options.

Does the --no-sandbox flag cause security risks?

Yes, the sandbox is a critical security layer. Only use --no-sandbox in trusted environments, such as isolated Docker containers, and avoid using it when navigating to untrusted websites.

Where is the browser actually stored on Linux?

By default, modern versions of Puppeteer store the browser in ~/.cache/puppeteer. Older versions stored it within the node_modules/puppeteer folder.

How do I update the downloaded browser?

The simplest way is to update the Puppeteer package via npm, which will trigger a download of the corresponding browser version for that release.