Docker NodeJS [email protected] - 如何解决启动chrome失败的问题?

问题描述 投票:0回答:1

在没有设置PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true和CHROMIUM_PATH usrbinchromium-browser的情况下。无铬包

printPdf() 错误。启动chrome失败! spawn usrsrcappnode_modulespuppeteer.local-chromiumlinux-706915chrome-linuxchrome ENOENT。


将PUPPETEER_SKIP_CHROMIUM_DOWNLOAD设置为true,CHROMIUM_PATH usrbinchromium-browser设置为true。带铬包

错误是有时缺少照片enter image description here

下面是我的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 [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

COPY package*.json ./

EXPOSE 3000

CMD [ "npm", "start"]

下面是我的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
});

js: Reference: GoogleChromuppepeteer

node.js docker chromium puppeteer alpine
1个回答
1
投票

只需将 headless 值为 false

browser = await puppeteer.launch({
  headless: true
});
© www.soinside.com 2019 - 2024. All rights reserved.