-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow screen capture #2237
Comments
You can use getUserMedia. |
Hi @zcbenz. Thanks for the response! getUserMedia is used to capture either audio or video from some input device, like a webcam or microphone. This is not what I'm trying to accomplish. What I'd like to do is take a screen grab of the elements on the user's screen, for example, allowing them to draw a rectangle of the area they'd like to capture, then save that picture to the Desktop. (In other words, this: https://support.apple.com/en-us/HT201361) I was able to accomplish this on Mac OS X using the var exec = require('child_process').exec;
exec('screencapture -R10,10,500,500 test.jpg', function (err, stdout, stderr) {
// work with the image within the app
}); But it would be nice to be able to accomplish this in a cross-platform way, as a method that is part of |
You can specify screen as input. |
Sorry to bring this up again, but Think this is a possibility to get add in as a new API? |
A simplified snippet function taking a screenshot, for the reference, function takeScreenShot (callback) {
let screenConstraints = {
mandatory: {
chromeMediaSource: "screen",
maxHeight: 1080,
maxWidth: 1920,
minAspectRatio: 1.77
},
optional: []
};
let session = {
audio: false,
video: screenConstraints
};
let streaming = false;
let canvas = document.createElement("canvas");
let video = document.createElement("video");
document.body.appendChild(canvas);
document.body.appendChild(video);
let width = screen.width;
let height = 0;
video.addEventListener("canplay", function(){
if (!streaming) {
height = video.videoHeight / (video.videoWidth / width);
if (isNaN(height)) {
height = width / (4 / 3);
}
video.setAttribute("width", width.toString());
video.setAttribute("height", height.toString());
canvas.setAttribute("width", width.toString());
canvas.setAttribute("height", height.toString());
streaming = true;
let context = canvas.getContext("2d");
if (width && height) {
canvas.width = width;
canvas.height = height;
context.drawImage(video, 0, 0, width, height);
canvas["toBlob"](function (data) {
video.pause();
video.src = "";
document.body.removeChild(video);
document.body.removeChild(canvas);
callback(data);
});
}
}
}, false);
navigator["webkitGetUserMedia"](session, function (stream) {
video.src = window["webkitURL"].createObjectURL(stream);
video.play();
}, function () {
console.error("Can't take a screenshot");
});
} |
You can use this library: https://github.com/mixalbl4-127/user-media-screenshot |
It would be nice to be able to create a screenshot of the user's screen, rather than just the contents of the BrowserWindow.
The text was updated successfully, but these errors were encountered: