I’m having trouble getting Puppeteer to work inside a Docker container. Every time I try to run my app, it throws an error saying Chrome browser isn’t found.
Error: Browser was not found at the configured executablePath (/usr/bin/google-chrome-stable)
throw new Error(`Browser was not found at the configured executablePath (${launchArgs.executablePath})`);
I’ve tried multiple approaches like installing Chrome manually in the container, using the official Puppeteer Docker image, and switching to puppeteer-core. Nothing seems to work. The error message always points to the same Chrome path even when I change the executablePath setting.
My app uses Puppeteer for PDF generation and is built with NestJs framework. Here’s my current setup:
Container setup:
# Base image
FROM ghcr.io/puppeteer/puppeteer:23.3.0
# Create app directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy source code
COPY . .
EXPOSE 4001
CMD ["npm", "run", "start:prod"]
Browser initialization code:
async onModuleInit() {
const launchOptions = {
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
browser: 'chrome',
} as puppeteer.PuppeteerLaunchOptions;
if (this.environment !== 'development') {
launchOptions.executablePath = '/usr/bin/google-chrome-stable)';
}
this.browserInstance = await puppeteer.launch(launchOptions);
this.currentPage = await this.browserInstance.newPage();
this.currentPage.setDefaultTimeout(0);
this.currentPage.setDefaultNavigationTimeout(0);
}
Running Puppeteer version 23.3.0. Any ideas what could be wrong?