Answers for "How To Take Screenshots In The Browser Using JavaScript"

0

How To Take Screenshots In The Browser Using JavaScript

const screenshotTarget = document.body;

html2canvas(screenshotTarget).then((canvas) => {
    const base64image = canvas.toDataURL("image/png");
    window.location.href = base64image;
});
Posted by: Guest on August-22-2021
0

How To Take Screenshots In The Browser Using JavaScript

const capture = async () => {
  const canvas = document.createElement("canvas");
  const context = canvas.getContext("2d");
  const video = document.createElement("video");

  try {
    const captureStream = await navigator.mediaDevices.getDisplayMedia();
    video.srcObject = captureStream;
    context.drawImage(video, 0, 0, window.width, window.height);
    const frame = canvas.toDataURL("image/png");
    captureStream.getTracks().forEach(track => track.stop());
    window.location.href = frame;
  } catch (err) {
    console.error("Error: " + err);
  }
};

capture();
Posted by: Guest on August-22-2021
0

How To Take Screenshots In The Browser Using JavaScript

const url2png = require('url2png')('API_KEY', 'PRIVATE_KEY');
const fs = require('fs');

app.get('/screenshot', (req, res) => {
	url2png.readURL(req.query.url, {}).pipe(fs.createWriteStream('screenshot.png'));
	res.json({success: true})
});
Posted by: Guest on August-22-2021

Code answers related to "How To Take Screenshots In The Browser Using JavaScript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language