1const screenshotTarget = document.body;
2
3html2canvas(screenshotTarget).then((canvas) => {
4 const base64image = canvas.toDataURL("image/png");
5 window.location.href = base64image;
6});
1const capture = async () => {
2 const canvas = document.createElement("canvas");
3 const context = canvas.getContext("2d");
4 const video = document.createElement("video");
5
6 try {
7 const captureStream = await navigator.mediaDevices.getDisplayMedia();
8 video.srcObject = captureStream;
9 context.drawImage(video, 0, 0, window.width, window.height);
10 const frame = canvas.toDataURL("image/png");
11 captureStream.getTracks().forEach(track => track.stop());
12 window.location.href = frame;
13 } catch (err) {
14 console.error("Error: " + err);
15 }
16};
17
18capture();
1const url2png = require('url2png')('API_KEY', 'PRIVATE_KEY');
2const fs = require('fs');
3
4app.get('/screenshot', (req, res) => {
5 url2png.readURL(req.query.url, {}).pipe(fs.createWriteStream('screenshot.png'));
6 res.json({success: true})
7});