what I am trying to achieve is add an option to my webApp that the users can screeshot the screen. I tried out some ready2use libraries like html2canvas and rasterizeHTML but I am experiensing problems with them. I found out a possible solution using the mediaDevices api, but there are several things that I want to change and not sure how. Here is my code:
navigator.mediaDevices.getDisplayMedia().then(stream =>
{
// Grab frame from stream
let track = stream.getVideoTracks()[0];
let capture = new ImageCapture(track);
let canvas = document.createElement('canvas');
capture.grabFrame().then(bitmap =>
{
track.stop();
canvas.width = bitmap.width;
canvas.height = bitmap.height;
canvas.getContext('2d').drawImage(bitmap, 0, 0);
let a = document.createElement("a");
document.body.appendChild(a);
a.href = canvas.toDataURL(`image/png`);
a.download = "screenshot.png";
a.click();
});
})
.catch(e => console.log(e));
Using this piece of code I am getting the options to choose from my available screens and pick what to screenshot. I have 2 problems with this:
Thanks in advance!