Answer the question
In order to leave comments, you need to log in
How once having created object of the browser it is constant to address it?
Hello.
I have the following in stock:
const express = require('express')
const puppeteer = require('puppeteer');
const app = express()
const port = 3000
app.get('/render', (req, res) => {
(async (req) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(req.query.url, {waitUntil: 'networkidle2'});
await page.emulateMediaType('screen')
await page.setViewport({
width: 400,
height: 1080,
deviceScaleFactor: 1,
});
console.log(req.query.url)
await page.pdf({
path: 'hn.pdf',
format: 'A4',
margin: {
top: 15,
bottom: 15,
right: 15,
left: 15
}
});
console.log('rendered')
await browser.close();
})(req)
res.send('123')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question