一、报错截图:
UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/www/wwwroot/avedex/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: error while loading shared libraries: libXcomposite.so.1: cannot open shared object file: No such file or directory
原因:
puppeteer没有找到库文件libXcomposite.so
解决:
安装对应依赖库如下:
#依赖库
yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 -y
#字体
yum install ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc -y
二、截图
UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
[1104/080019.210605:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported.
原因:作为root用户 不使用 --no-sandbox 运行是不被支持的
解决:使用--no-sandbox
代码如下:
var url = 'https://www.xxx.com/xxx;
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({args: ['--no-sandbox']});
const page = await browser.newPage();
await page.goto(url);