问题
Without setting PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true and CHROMIUM_PATH /usr/bin/chromium-browser Without chromium package
Error for printPdf()
Error: Failed to launch chrome! spawn /usr/src/app/node_modules/puppeteer/.local-chromium/linux-706915/chrome-linux/chrome ENOENT
With setting PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true and CHROMIUM_PATH /usr/bin/chromium-browser With chromium package
Error is missing photos sometimes
Below is my Dockerfile:
FROM alpine:latest
WORKDIR /usr/src/app
RUN chmod -R 444 /etc/apk/
RUN echo "ipv6" >> /etc/modules
RUN set -x \
&& apk update \
&& apk upgrade \
RUN apk add -f
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV CHROMIUM_PATH /usr/bin/chromium-browser
# Installs latest Chromium package.
RUN apk add --no-cache \
chromium \ ### with this, it is okay
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont \
nodejs \
npm \
yarn
RUN yarn add puppeteer@2.0.0 adal-node@0.2.0 azure-keyvault@3.0.4 azure-sb@0.11.1 azure-storage@2.10.3 http@0.0.0
COPY package*.json ./
EXPOSE 3000
CMD [ "npm", "start"]
Below is my puppeteer.js:
browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser', // if without using chromium package: executablePath: process.env.CHROMIUM_PATH,
args: ['--no-sandbox', '--enable-font-antialiasing', '--font-render-hinting=medium'],
timeout: LOAD_TIMEOUT,
headless: true
});
Reference: GoogleChrome/puppeteer
回答1:
Just make the headless
value to false
browser = await puppeteer.launch({
headless: true
});
来源:https://stackoverflow.com/questions/58746052/docker-nodejs-puppeteer2-0-0-how-do-fix-failed-to-launch-chrome-issue