Fix Puppeteer Chrome launch in Alpine Linux Docker
ci/woodpecker/push/woodpecker Pipeline was successful Details

- Install Chromium and required system libraries (nss, freetype, harfbuzz, etc.)
- Set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD to use system Chromium
- Add additional Chrome args for better compatibility in container
- Configure package.json to skip Chromium download
- Fixes 'Failed to launch the browser process' error
This commit is contained in:
Colin 2025-11-30 16:40:29 -05:00
parent 19182d6d21
commit 8b1a1e23bf
Signed by: colin
SSH Key Fingerprint: SHA256:nRPCQTeMFLdGytxRQmPVK9VXY3/ePKQ5lGRyJhT5DY8
3 changed files with 31 additions and 3 deletions

View File

@ -1,7 +1,21 @@
FROM caddy:2.7-alpine
# Install dependencies
RUN apk add --no-cache nodejs npm bash
# Install dependencies including Chromium and required libraries for Puppeteer
RUN apk add --no-cache \
nodejs \
npm \
bash \
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont
# Set Puppeteer to use system Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# Set working directory
WORKDIR /srv

View File

@ -174,9 +174,20 @@ async function main() {
console.log(`Local server started on port ${PORT}\n`);
// Launch browser
// Use system Chromium if available (in Docker), otherwise use Puppeteer's bundled Chrome
const browser = await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox']
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-accelerated-2d-canvas',
'--no-first-run',
'--no-zygote',
'--single-process',
'--disable-gpu'
]
});
try {

View File

@ -12,5 +12,8 @@
"description": "",
"dependencies": {
"puppeteer": "^21.0.0"
},
"puppeteer": {
"skipChromiumDownload": true
}
}