Glitch + Puppeteer


#1

I’m trying to get a basic Puppeteer example working. It seems to be hanging on something. Any ideas?


#2

https://www.developers.google.com/web/tools/puppeteer isn’t a valid URL, so the page.goto hangs with err_name_not_resolved. You want https://developers.google.com/web/tools/puppeteer I think.


#3

Whoops, good catch. However, still doesn’t work after providing a valid URL.


#4

I started a discussion on the Puppeteer side of things, too: https://github.com/GoogleChrome/puppeteer/issues/2143


#5

you can see why it fails in the Logs:

TypeError: path must be absolute or specify root to res.sendFile
    at ServerResponse.sendFile (/rbd/pnpm-volume/2ba2fb12-3226-4fc6-a9ae-a9cf09896d19/node_modules/.registry.npmjs.org/express/4.16.2/node_modules/express/lib/response.js:421:11)
    at app.get (/app/server.js:14:14)
    at <anonymous>

Basically, the issue is that when the endpoint fails, you didn’t write a response for the browser, but only in the logs. Try adding this in the catch, after console.log:

response.status(503).end(error.message);

This way you can see the error from the preview too :slight_smile:


#6

By the way, to actually fix the error you can write:

response.sendFile('/app/puppeteer.png');

instead of

response.sendFile('puppeteer.png');

#7

Feel free to remix https://glitch.com/edit/#!/puppeteer-sample


#8

Beautiful, much easier than expected. Sorry for the pilot error, I should’ve caught that. Thanks @etamponi & @Gareth