我正在尝试在 bash 脚本中使用 pageres 来抓取 heruko 中的屏幕截图。但跑步佩雷斯withalpine:latest
会引发木偶操作者错误。
at onClose (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
at ChildProcess(/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:184:79)
我按照以下位置的故障排除文档进行操作傀儡师 git并将这些行添加到我的 dockerfile 中:
# Installs latest Chromium (92) package.
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont \
nodejs \
yarn
# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# Puppeteer v10.0.0 works with Chromium 92.
RUN yarn add [email protected]
# Add user so we don't need --no-sandbox.
RUN addgroup -S pptruser && adduser -S -G pptruser pptruser \
&& mkdir -p /home/pptruser/Downloads /app \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /app
我还尝试在无头模式下使用 Firefox 来抓取屏幕截图,这也会引发错误......
*** You are running in headless mode.
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.323898) [GFX1-]: glxtest: libpci missing
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.323898) |[1][GFX1-]: glxtest: libGL.so.1 missing (t=0.32393) [GFX1-]: glxtest: libGL.so.1 missing
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.323898) |[1][GFX1-]: glxtest: libGL.so.1 missing (t=0.32393) |[2][GFX1-]: glxtest: libEGL missing (t=0.323941) [GFX1-]: glxtest: libEGL missing
Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.323898) |[1][GFX1-]: glxtest: libGL.so.1 missing (t=0.32393) |[2][GFX1-]: glxtest: libEGL missing (t=0.323941) |[3][GFX1-]: No GPUs detected via PCI (t=0.323959) [GFX1-]: No GPUs detected via PCI
但遗憾的是没有任何效果。我可以有解决办法或更好的方法吗?
Chromium 版本 - 93.0.4577.82,Firefox 版本 - 94.0,Puppeteer 版本 - 10.0.0
答案1
这对我有用。您可以尝试一下并让我知道它是否也适合您。
FROM node:17-alpine
ENV CHROME_BIN="/usr/bin/chromium-browser" \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
RUN set -x \
&& apk update \
&& apk upgrade \
&& apk add --no-cache \
udev \
ttf-freefont \
chromium \
&& npm install puppeteer
NodeJ 中的用法
const browser = await puppeteer.launch({
headless: true,
executablePath: '/usr/bin/chromium-browser',
args: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage'
]
})