Fix Chrome Not Found with Puppeteer in Laravel Sail
In this article
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
puppeteerpackage already added to yourpackage.json.
Step-by-Step
- 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:
This will create aphp artisan sail:publishdockerdirectory in your project root containing the Dockerfiles for your services (usuallylaravel.test). - Modify the Dockerfile
Opendocker/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 whereapt-get installis called and addchromiumto the list of packages. If you want a dedicated block for clarity, add this before the finalCMDorENTRYPOINT:
Note: Depending on the base image (Ubuntu/Debian), the package name might beRUN apt-get update && apt-get install -y chromium-browser chromiumchromiumorchromium-browser. Including both or checking the specific distribution's package manager is recommended. - Rebuild the Sail Containers
Since you have modified the Dockerfile, you must rebuild the image for the changes to take effect. Run:
The./vendor/bin/sail build --no-cache--no-cacheflag ensures that the package manager actually fetches the latest version of Chromium rather than relying on a cached layer. - Restart the Containers
Once the build is complete, start your containers again:./vendor/bin/sail up -d - 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 theexecutablePathoption:
*Note: Ifconst browser = await puppeteer.launch({ executablePath: '/usr/bin/chromium-browser', args: ['--no-sandbox', '--disable-setuid-sandbox'] });/usr/bin/chromium-browserdoes not work, runwhich chromiumorwhich chromium-browserinside the container viasail shellto find the exact path.* - 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-sandboxand--disable-setuid-sandboxflags in theargsarray as shown in the previous step.
Common Mistakes
- Forgetting to rebuild: Many developers add the package to the Dockerfile but run
sail upwithoutsail 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-chromewhen the package installed waschromium. Always verify the path using thewhichcommand inside the container. - Installing via NPM only: Running
npm install puppeteerdoes not install the Linux system libraries (likelibX11orlibnss3) required to actually execute the browser.
Tips
- Use puppeteer-core: If you are manually providing the executable path, consider using
puppeteer-coreinstead ofpuppeteer. This reduces yournode_modulessize because it doesn't attempt to download the bundled Chrome binary. - Verify installation: Use
./vendor/bin/sail shellto enter the container and typechromium --versionto 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 addinglibnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1to theapt-get installcommand. - 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 callawait browser.close()in afinallyblock.
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.