4

I am trying to use Google Chrome Puppeteer in the predix-web-starter app. When I run the code locally on Windows, it runs flawlessly. After I push it to Predix, and when I run the part containing the Puppeteer code, it results in an error. There seems to be some missing library issues (not sure what). In short, how can I get Puppeteer to run on Predix?

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

Puppeteer code:

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();
})();

Logs:

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
Arjun Mudhaliyar
  • 156
  • 3
  • 10

3 Answers3

1

Recently found that using the cloudfoundry/apt-buildpack and the cloudfoundry/nodejs-buildpack, the shared libraries can be installed by including them in apt.yml. However predix is not allowing multibuildpacks push so i tried to use cloudfoundry/multi-buildpack without success for unknown reason. The way i solve it was creating a custom buildpack taking the code from apt, put it on nodejs buildpack and then including git repository url on the manifest.yml. This is my custom buildpack.

0

This is because Chrome likely needs more packages installed to work properly on that host. There's an excellent troubleshooting document here, assuming you have some control over how the environment is provisioned.

The other options is to use another service that runs Chrome for you (which you can get working on AWS or Google Cloud). It's quite a process to do, which is why I wrote https://browserless.io, which is turnkey and supports puppeteer 0.11.0 and 0.12.0.

Hope that gets you on the right path, good luck!

browserless
  • 2,090
  • 16
  • 16
  • I have no control on the environment. So, mostly I'll have to figure out another way or use another service as you suggested. Thanks for your help! – Arjun Mudhaliyar Nov 15 '17 at 06:08
0

Looks like puppeteer is trying to use a "shared library" which is missing or you don't have access to. In the Predix Cloud Foundry environment, your access to the server OS is very limited. You're only allowed to use resources inside the container, which allows scaling to happen easily.

What's your goal? Trying to run browser tests? You might try selenium with Sauce Labs, or Travis.

gstroup
  • 1,064
  • 8
  • 16
  • 1
    No, The goal is to render HTML in the back-end so as to generate a PDF once the code is rendered. No UI is involved, hence back-end rendering is being used. Thank you for your help! – Arjun Mudhaliyar Nov 15 '17 at 06:10