I’m working on a NestJS app that uses Puppeteer for PDF generation, and I’m having trouble getting it to work inside a Docker container.
The main issue is that Chrome browser cannot be found at the expected location. Here’s the error I keep getting:
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 several approaches including using the official Puppeteer Docker image, installing Chrome manually in the container, and switching to puppeteer-core, but nothing seems to work. The error message always points to the same Chrome path even when I try to modify the executablePath.
Here’s my current Docker setup:
# Using official Puppeteer image
FROM ghcr.io/puppeteer/puppeteer:23.3.0
# Set working 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"]
And here’s how I’m configuring the browser in my service:
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);
}
Using Puppeteer version 23.3.0. Any suggestions on how to properly configure Chrome in the Docker environment would be really helpful!