是否可以在 Ubuntu Server 16.04 上运行Puppeteer ?我得到这个错误。
(node:23213) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/root/bin/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/root/bin/node_modules/puppeteer/lib/Launcher.js:750:14)
at Interface.<anonymous> (/root/bin/node_modules/puppeteer/lib/Launcher.js:739:50)
at Interface.emit (events.js:333:22)
at Interface.close (readline.js:414:8)
at Socket.onend (readline.js:192:10)
at Socket.emit (events.js:333:22)
at endReadableNT (_stream_readable.js:1201:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:23213) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:23213) [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.
如何解决此故障并让应用程序运行?
我修好了它。我必须更新我的 Linux (sudo-apt get update) 然后获取库。如果您不更新它,它将无法正常工作。
之后,我必须添加
'--no-sandbox',
启动代码(来自 myapp.js)。使用最新版本的铬,这对我有用。注意最近添加的依赖项。
如果您使用的是 Docker,则可以将以下内容添加到 Docker 文件中。我也用 Docker 进行了测试,这很有效。
在调用 puppeteer 时添加了参数
'--no-sandbox'
。这与Lmao的建议相同。如果没有这个选项,我无法让它工作。作为参考,我使用的是 Ubuntu 20,但这应该适用于任何发行版。