【问题标题】:Docker NodeJS Puppeteer@2.0.0 - How do fix Failed to launch chrome! issueDocker NodeJS Puppeteer@2.0.0 - 如何修复无法启动 chrome!问题
【发布时间】:2020-09-03 16:45:02
【问题描述】:

不设置 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true 和 CHROMIUM_PATH /usr/bin/chromium-browser 无铬包装

printPdf() 出错
错误:无法启动 chrome! spawn /usr/src/app/node_modules/puppeteer/.local-chromium/linux-706915/chrome-linux/chrome ENOENT


通过设置 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 为 true 和 CHROMIUM_PATH /usr/bin/chromium-browser 带铬包

错误是有时会丢失照片

下面是我的 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"]

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

参考:GoogleChrome/puppeteer

【问题讨论】:

    标签: node.js docker chromium puppeteer alpine


    【解决方案1】:

    只需将headless 值设为false

    browser = await puppeteer.launch({
      headless: true
    });
    

    【讨论】:

    • 为什么是无头假?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2019-02-15
    • 1970-01-01
    • 2018-04-22
    • 2019-11-21
    • 2021-11-12
    • 2019-11-16
    相关资源
    最近更新 更多