gpt4 book ai didi

node.js - Docker Node :Alpine-12: how to install Chromium 73 in Dockerfile?

转载 作者:太空宇宙 更新时间:2023-11-03 21:51:01 26 4
gpt4 key购买 nike

因为我想运行 Puppeteer@1.19 但在 page.pdf() 中遇到错误。

一些 blob 刚刚提到将 Chromium 从版本 76 降级到 73。如何使用 node:alpine-12 在 Dockerfile 中执行此操作?谢谢

以下是我的设置(chromium 版本是 76):

FROM node:12-alpine
##########
## Setting for using Puppeteer (for using node:XX-alpine)
##########
ENV CHROME_BIN="/usr/bin/chromium-browser"\
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
##########
## Update and Install packages
##########
RUN set -x \
&& apk update \
&& apk upgrade \
&& echo "127.0.0.1 localhost" >> /etc/hosts \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
# add the packages
## g++: used to install NodeJS related packages
## chromium: used to run Puppeteer
&& apk add --no-cache g++ chromium

尝试将最后一行从 chromium 更改为 chromium-browser@73chromium@73 但遇到以下错误:

The repository tag for world dependency 'chromium@73' does not exist

仅供引用,当我刚刚安装 chromium 并运行下面的 NodeJS 代码时出现错误:

Line239: await page.pdf({
path: TEMP_DIR + filename,
format: 'A4',
printBackground: true
});

printPdf() Error
Error: Protocol error (IO.read): Invalid parameters handle: string value expected
 at /usr/src/app/node_modules/puppeteer/lib/Connection.js:183:56
 at new Promise ()
 at CDPSession.send (/usr/src/app/node_modules/puppeteer/lib/Connection.js:182:12)
 at Function.readProtocolStream (/usr/src/app/node_modules/puppeteer/lib/helper.js:241:37)
 at async Page.pdf (/usr/src/app/node_modules/puppeteer/lib/Page.js:988:12)
 at async printPdf (/usr/src/app/puppeteer.js:239:9)
 at async /usr/src/app/puppeteer.js:129:21
 -- ASYNC --
 at Page. (/usr/src/app/node_modules/puppeteer/lib/helper.js:111:15)
 at printPdf (/usr/src/app/puppeteer.js:239:20)
 at processTicksAndRejections (internal/process/task_queues.js:85:5)
 at async /usr/src/app/puppeteer.js:129:21 { message: 'Protocol error (IO.read): Invalid parameters handle: string value expected'
}

最佳答案

nodejs 基础镜像中使用的边缘分支中不存在 chromium73。您必须将分支设置为 v3.10 才能下载 chromium73。

alpine chromium&branch=v3.10

FROM node:12-alpine
RUN apk add --no-cache chromium --repository=http://dl-cdn.alpinelinux.org/alpine/v3.10/main

验证安装

docker run -it --rm myalpine ash -c“apk -e info chromium”

关于node.js - Docker Node :Alpine-12: how to install Chromium 73 in Dockerfile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57714810/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com