puppeteer express PDF export
const puppeteer = require ('puppeteer');
//const express = require('express');
var express = require("@runkit/runkit/express-endpoint/1.0.0");
var app = express(exports);
const browser = await puppeteer.launch({args: ['--no-sandbox']}); // usually you don't need this options, this are for running on runkit properly
const main = async () => {
const page = await browser.newPage();
await page.goto('https://example.com');
const pdf = await page.pdf();
return pdf;
}
app.get('/', async function (req, res) {
const pdf = await main();
res.contentType("application/pdf");
res.send(pdf);
});
/* not required on runkit
app.listen(3000, function(){
console.log('Listening on 3000');
});
*/
no comments