将Google Chrome Puppeteer应用推向Predix时出错

时间:2017-11-10 09:51:23

标签: cloudfoundry puppeteer predix

我正在尝试在predix-web-starter应用中使用Google Chrome Puppeteer。当我在Windows上本地运行代码时,它运行完美。在我将它推送到Predix之后,当我运行包含Puppeteer代码的部分时,它会导致错误。似乎有一些遗漏的库问题(不确定是什么)。 简而言之,我怎样才能让Puppeteer在Predix上运行?

Predix-web-starter:https://github.com/PredixDev/predix-webapp-starter Puppeteer:https://www.npmjs.com/package/puppeteer

Puppeteer代码:

const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle'});
await page.pdf({path: 'hn.pdf', format: 'A4'});
await browser.close();
})();

日志:

2017-11-07T12:40:16.19+0530 [App/0] ERR /home/vcap/app/node_modules/puppeteer/.local-chromium/linux-508693/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
2017-11-07T12:40:16.19+0530 [App/0] ERR TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Interface.close (readline.js:319:8)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at endReadableNT (_stream_readable.js:974:12)
2017-11-07T12:40:16.19+0530 [App/0] ERR Potentially unhandled rejection [3] Error: Failed to launch chrome!
2017-11-07T12:40:16.19+0530 [App/0] ERR     at onClose (/home/vcap/app/node_modules/puppeteer/node6/Launcher.js:262:14)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at emitNone (events.js:91:20)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Interface.emit (events.js:186:7)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at _combinedTickCallback (internal/process/next_tick.js:74:11)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Interface.helper.addEventListener (/home/vcap/app/node_modules/puppeteer/node6/Launcher.js:251:50)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Socket.onend (readline.js:106:10)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at emitNone (events.js:91:20)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Socket.emit (events.js:186:7)
2017-11-07T12:41:15.21+0530 [RTR/2] OUT puppeter-arjun-app.run.aws-usw02-pr.ice.predix.io - [2017-11-07T07:10:16.196+0000] "GET /puppeteer HTTP/1.1" 502 0 67 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36" "10.72.11.93:2263" "10.72.2.213:61322" x_forwarded_for:"-" x_forwarded_proto:"http" vcap_request_id:"7d0f3007-914a-42d4-536d-b94eb8d2fb6c" response_time:59.022647288 app_id:"02063159-96d9-43c5-a3e9-77f4e72339f4" app_index:"-" x_b3_traceid:"4f11f468be4b6817" x_b3_spanid:"4f11f468be4b6817" x_b3_parentspanid:"-"
2017-11-07T12:41:15.21+0530 [RTR/2] OUT

3 个答案:

答案 0 :(得分:0)

这是因为Chrome可能需要安装更多软件包才能在该主机上正常运行。有一个很好的故障排除文档here,假设您可以控制环境的配置方式。

其他选项是使用另一种为您运行Chrome的服务(您可以在AWS或Google Cloud上运行)。这是一个很好的过程,这就是为什么我写了https://browserless.io,这是一个交钥匙并且支持puppeteer 0.11.0和0.12.0。

希望能让你走上正确的道路,祝你好运!

答案 1 :(得分:0)

看起来puppeteer正在尝试使用"共享库"缺少或您无法访问。在Predix Cloud Foundry环境中,您对服务器操作系统的访问非常有限。您只允许使用容器内的资源,这样可以轻松进行扩展。

你的目标是什么?试图运行浏览器测试?您可以尝试使用Sauce Labs或Travis进行硒。

答案 2 :(得分:0)

最近发现,使用cloudfoundry/apt-buildpackcloudfoundry/nodejs-buildpack,可以通过将共享库包含在apt.yml中来安装它们。但是predix不允许multibuildpacks push,因此出于未知原因,我尝试使用cloudfoundry/multi-buildpack而不成功。我解决的方法是创建一个自定义buildpack,从apt接收代码,将其放在nodejs buildpack上,然后在manifest.yml上包括git repository url。 这是我的custom buildpack