User Agents

Web browsers and everyday web tech, explained

Fix Chrome Not Found with Puppeteer in Laravel Sail

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To fix the "Chrome not found" error when using Puppeteer in Laravel Sail, you must install the Chromium browser and its required system dependencies directly into the Sail Docker container. Because Puppeteer's default installation often fails to download a compatible browser binary within a Linux container, or the container lacks the shared libraries needed to run the browser, you must modify the Dockerfile to ensure the environment is properly provisioned.

What You'll Need

  • A working Laravel Sail installation.
  • Administrative access to your project directory to modify the Dockerfile.
  • Basic familiarity with the terminal and Docker commands.
  • The puppeteer package already added to your package.json.

Step-by-Step

  1. Publish the Sail Dockerfiles
    By default, Sail uses internal Dockerfiles. To modify them, you need to publish them to your project directory. Run the following command in your terminal:
    php artisan sail:publish
    This will create a docker directory in your project root containing the Dockerfiles for your services (usually laravel.test).
  2. Modify the Dockerfile
    Open docker/8.x/laravel.test (the version number may vary based on your PHP version) in your code editor. You need to add the installation commands for Chromium. Find the section where apt-get install is called and add chromium to the list of packages. If you want a dedicated block for clarity, add this before the final CMD or ENTRYPOINT:
    RUN apt-get update && apt-get install -y chromium-browser chromium
    Note: Depending on the base image (Ubuntu/Debian), the package name might be chromium or chromium-browser. Including both or checking the specific distribution's package manager is recommended.
  3. Rebuild the Sail Containers
    Since you have modified the Dockerfile, you must rebuild the image for the changes to take effect. Run:
    ./vendor/bin/sail build --no-cache
    The --no-cache flag ensures that the package manager actually fetches the latest version of Chromium rather than relying on a cached layer.
  4. Restart the Containers
    Once the build is complete, start your containers again:
    ./vendor/bin/sail up -d
  5. Configure Puppeteer to use the Installed Binary
    Puppeteer will still try to look for its own bundled version of Chrome, which is often missing or incompatible. You must explicitly tell Puppeteer to use the system-installed Chromium binary. In your Laravel code where you launch the browser, use the executablePath option:
    const browser = await puppeteer.launch({
                executablePath: '/usr/bin/chromium-browser', 
                args: ['--no-sandbox', '--disable-setuid-sandbox']
            });
    *Note: If /usr/bin/chromium-browser does not work, run which chromium or which chromium-browser inside the container via sail shell to find the exact path.*
  6. Add Essential Sandbox Flags
    Docker containers run as root by default or in restricted environments that conflict with Chrome's sandbox. To prevent the browser from crashing on launch, you must include the --no-sandbox and --disable-setuid-sandbox flags in the args array as shown in the previous step.

Common Mistakes

  • Forgetting to rebuild: Many developers add the package to the Dockerfile but run sail up without sail build. The container will continue to use the old image without Chromium.
  • Omitting the --no-sandbox flag: Chrome's security sandbox requires privileges that Docker containers typically do not have. Without this flag, Puppeteer will throw a "Failed to launch the browser process" error.
  • Using the wrong binary path: Assuming the path is /usr/bin/google-chrome when the package installed was chromium. Always verify the path using the which command inside the container.
  • Installing via NPM only: Running npm install puppeteer does not install the Linux system libraries (like libX11 or libnss3) required to actually execute the browser.

Tips

  • Use puppeteer-core: If you are manually providing the executable path, consider using puppeteer-core instead of puppeteer. This reduces your node_modules size because it doesn't attempt to download the bundled Chrome binary.
  • Verify installation: Use ./vendor/bin/sail shell to enter the container and type chromium --version to confirm the browser is installed and accessible.
  • Memory Limits: Headless Chrome is memory-intensive. If your container crashes during PDF generation or scraping, increase the memory limit allocated to Docker in your Docker Desktop settings.

Troubleshooting

If you still encounter errors after following these steps, check the following:

  • Missing Shared Libraries: If you see errors like error while loading shared libraries: libatk-1.0.so.0, it means Chromium is installed but its dependencies are not. You may need to add a comprehensive list of dependencies to your Dockerfile. A common fix is adding libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 to the apt-get install command.
  • Permission Denied: Ensure the user running the process inside the container has permission to execute the binary in /usr/bin/.
  • Zombie Processes: Puppeteer sometimes leaves "zombie" Chrome processes open. If you notice memory leaking, use a package like tini (which Sail includes by default) or ensure you call await browser.close() in a finally block.

Frequently Asked Questions

Why doesn't Puppeteer just work out of the box in Sail?

Puppeteer downloads a version of Chromium tailored for the host OS. In a Docker environment, the underlying Linux distribution often lacks the specific GUI libraries and dependencies required to run a browser, even in headless mode.

Do I need to install Chrome on my local machine?

No. Because Laravel Sail runs inside a Docker container, the browser must be installed inside the container image, not on your Windows, macOS, or Linux host machine.

What is the difference between Chromium and Chrome?

Chromium is the open-source project that serves as the foundation for Google Chrome. In Linux server environments, Chromium is preferred because it is easier to install via package managers like apt.

Will this slow down my Docker build time?

Yes, the initial build will take longer because it has to download and install the browser and its dependencies. However, subsequent builds will be fast unless you change the Dockerfile.

Can I use this for generating PDFs?

Yes, this setup is the standard way to enable PDF generation using libraries like Browsershot, which relies on Puppeteer and a working Chromium installation.