linux服务器上安装puppeteer

安装

1
cnpm install -g puppeteer

可能的报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(node:32) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
/usr/local/lib/node_modules/puppeteer/.local-chromium/linux-543305/chrome-linux/chrome: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory

TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

at onClose (/usr/local/lib/node_modules/puppeteer/lib/Launcher.js:246:14)
at Interface.helper.addEventListener (/usr/local/lib/node_modules/puppeteer/lib/Launcher.js:235:50)
at Interface.emit (events.js:185:15)
at Interface.close (readline.js:379:8)
at Socket.onend (readline.js:152:10)
at Socket.emit (events.js:185:15)
at endReadableNT (_stream_readable.js:1106:12)
at process._tickCallback (internal/process/next_tick.js:114:19)
(node:32) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:32) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

解决

1
yum install chromium