frinyvonnick / node-html-to-image

A Node.js module that generates images from HTML
https://www.npmjs.com/package/node-html-to-image
Apache License 2.0
827 stars 125 forks source link

V4.0.0 get Error: Could not find Chrome (ver. 119.0.6045.105) #218

Open brickyang opened 11 months ago

brickyang commented 11 months ago

I have been using node-html-to-image for two years and it worked well. Recently I updated all dependencies including this package to v4.0.0 and it doesn't work any more.

Call nodeHtmlToImage() it just thrown an error:

ERROR 1016 nodejs.Error: Unable to launch browser, error message: Could not find Chrome (ver. 119.0.6045.105). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at Cluster.<anonymous> (/app/node_modules/puppeteer-cluster/dist/Cluster.js:119:23)
    at Generator.throw (<anonymous>)
    at rejected (/app/node_modules/puppeteer-cluster/dist/Cluster.js:6:65)

I googled every error message, read many pages in GIthub and Stack Overflow and tried different version of nodejs and Chrome but got nothing.

Eventually I modified package.json with node-html-to-image ^3, got ERROR 54 nodejs.Error: Unable to launch browser, error message: Could not find expected browser (chrome) locally. Runnpm installto download the correct Chromium revision.

Then I run node node_modules/puppeteer/install.js and enerything is GOOD now.

I have no idea what happened.

------ BACKGROUND ------

I use a Docker container to run my app. The base image is node:20-bullseye-slim and installed Chrome manually. My Dockerfile:

FROM node:20-bullseye-slim

ENV TZ=Asia/Shanghai \
    DEBIAN_FRONTEND=noninteractive \
    LANG=zh_CN.UTF-8

RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone \
    && dpkg-reconfigure --frontend ${DEBIAN_FRONTEND} tzdata \
    && apt-get -y update \
    && apt-get install -y wget gnupg2 libxss1 locales \
    && sed -ie 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen \
    && locale-gen \
    && mkdir -p /usr/share/fonts/truetype/SourceHanSerifCN/ \
    && wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    && apt-get -y update && apt-get install -y google-chrome-stable \
    && rm -rf /var/lib/apt/lists/*

COPY SourceHanSerifCN*.otf /usr/share/fonts/truetype/SourceHanSerifCN/

CMD [ "node" ]

My puppeteer args is:

puppeteerArgs: {
        args: [
          '--disable-dev-shm-usage',
          '--enable-sync',
          '--enable-background-networking',
          '--no-sandbox',
          '--disable-setuid-sandbox',
          '--disable-gpu',
          '--renderer',
          '--no-service-autorun',
          '--no-experiments',
          '--no-default-browser-check',
          '--disable-webgl',
          '--disable-threaded-animation',
          '--disable-threaded-scrolling',
          '--disable-in-process-stack-traces',
          '--disable-histogram-customizer',
          '--disable-gl-extensions',
          '--disable-extensions',
          '--disable-composited-antialiasing',
          '--disable-canvas-aa',
          '--disable-3d-apis',
          '--disable-accelerated-2d-canvas',
          '--disable-accelerated-jpeg-decoding',
          '--disable-accelerated-mjpeg-decode',
          '--disable-app-list-dismiss-on-blur',
          '--disable-accelerated-video-decode',
          '--mute-audio',
          '--log-level=3',
          '--disable-infobars',
          '--disable-web-security',
          '--disable-site-isolation-trials',
          '--ignore-gpu-blacklist',
          '--ignore-certificate-errors',
          '--ignore-certificate-errors-spki-list',
          '--disable-default-apps',
          '--enable-features=NetworkService',
          '--no-first-run',
          '--no-zygote',
          '--unlimited-storage',
          '--headless=new',
          '--disable-dev-shm-usage',
        ],
        headless: true,
        ignoreHTTPSErrors: true,
      }
masarbazi commented 4 months ago

Same issue🥲 no updates?

frinyvonnick commented 1 month ago

Did you check the troubleshooting section of Puppeteer documentation https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md? Since, I updated Puppeteer you might do some changes on your part. That is why I made a major version to warn about the fact it might contains breaking changes on puppeteer side.