-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (25 loc) · 816 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const express = require('express')
const { chromium } = require('playwright')
const app = express()
const fs = require('fs')
app.set('view-engine', 'ejs')
app.set('views', './views')
const PORT = 8000
app.listen(PORT, () => {
console.log(`Server is running on ${PORT}`)
})
app.get('/', (req, res) => {
return res.render("index.ejs")
})
app.get("/screenshot", async (req, res) => {
const url = req.query.url
let browser = await chromium.launch();
let page = await browser.newPage();
await page.setViewportSize({ width: 1366, height: 768 }); //Most Popular Resolution
await page.goto(url);
const buffer = await page.screenshot();
await browser.close();
res.header('Content-Type','image/png')
res.header('Content-Disposition','inline')
return res.send(buffer)
})