I am trying to use puppeteer with node.js which is working fine on my local Mac OS but When the code goes through CI pipeline it throws following error
error: Error: Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
I have tried Troubleshooting docs but the given solutions are not working in my case
* docker -
ENV CHROME_BIN="/usr/bin/chromium-browser" \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
RUN set -x \
&& apk update \
&& apk upgrade \
&& apk add --no-cache \
udev \
ttf-freefont \
chromium \
&& npm install puppeteer
*Node-
const browser = await puppeteer.launch({
headless: true,
executablePath: '/usr/bin/chromium-browser',
args: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage'
]
})
I had the same issue when I was trying to run the node container in docker.
My environment is using:
You can run ldd chrome | grep not on a Linux machine to check which dependencies are missing.
Go inside the running docker container -
docker exec -it [CONTAINER ID] /bin/bash. Run the above command inside this path to find missing dependencies - /node_modules/puppeteer/.local-chromium/linux-[970485]/chrome-linux
For more detailed steps, you can follow this well explained answer. Thanks to @dhilt for this answer.
Add the missing dependencies in the docker file.
Dockerfile (I didn't need to install chrome or chromium-browser)
RUN apt-get update \
&& apt-get -f install -y --no-install-recommends \
fonts-liberation \
libgtk-3-0 \
libwayland-client0 \
xdg-utils \
libu2f-udev \
libvulkan1 \
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
&& rm -rf /var/lib/apt/lists/*
nodefile.js (The bowser is not installed locally so no need to set executablePath)
// linux
let browser = await puppeteer.launch({
headless: true,
args: ['-no-sandbox']
});
Please mark the response as answered if it is helpful, so that its helpful for other community members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With