Fix Puppeteer Chrome launch in Alpine Linux Docker
ci/woodpecker/push/woodpecker Pipeline was successful
Details
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:
parent
19182d6d21
commit
8b1a1e23bf
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -12,5 +12,8 @@
|
|||
"description": "",
|
||||
"dependencies": {
|
||||
"puppeteer": "^21.0.0"
|
||||
},
|
||||
"puppeteer": {
|
||||
"skipChromiumDownload": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue