1

Using the following code:

function captureScreen(size) {
    navigator.webkitGetUserMedia({
        audio: false,
        video: {
            mandatory: {
                chromeMediaSource: 'desktop',
                minWidth: size.width,
                maxWidth: size.width,
                minHeight: size.height,
                maxHeight: size.height,
                minFrameRate: 1,
                maxFrameRate: 1
            }
        }
    }, gotStream, getUserMediaError);

    function gotStream(stream) {
        var video = document.createElement('video');
        video.addEventListener('loadedmetadata',function(){
            var canvas = document.createElement('canvas');
            canvas.width = this.videoWidth;
            canvas.height = this.videoHeight;
            var context = canvas.getContext("2d");
            context.drawImage(this, 0, 0);
        },false);
        video.src = URL.createObjectURL(stream);
    }

    function getUserMediaError(e) {
        console.log('getUserMediaError: ' + JSON.stringify(e, null, '---'));
    }
}

Gives me the following result:

enter image description here

Notice how the right side of the image is slightly wrapped to the left side? For some reason, this happens on my laptop (1366x768), a friend's laptop (1366x768), but not my desktop (3840x1080 dual screen). the size parameter passed to the function is always the correct and actual size of the entire desktop area. Even when I hardcode the min and max width / height, I get the same result. Is there any way to fix this? Am I doing something wrong?

I'm building an Electron app which needs to take a screenshot of the user's desktop. There's also nothing else on the web page, and I am using a reset CSS.

driima
  • 623
  • 1
  • 11
  • 28
  • Does the amount of left-wrapping vary with the screen width? – raduation Jul 09 '16 at 20:36
  • @raduation It's the same, 8 pixels left-wrapped. I made a mistake by the way, my friend's laptop is the same resolution as my laptop (1366x768) – driima Jul 09 '16 at 20:48
  • Can you try setting different screen resolutions on your laptop and see what results you get? Maybe there is a bug in the capture where it expects a multiple of 10. Total speculation here, but maybe! – raduation Jul 09 '16 at 20:51
  • @raduation at 1280x720, it's the same 8 pixel left-wrapping. I even set the min and max width / height to those numbers in the script so I know it's capturing the exact size. – driima Jul 09 '16 at 20:57
  • On your laptop, is there a scroll feature that perhaps has an 8-pixel scrollbar on the right? – raduation Jul 09 '16 at 21:01
  • @raduation No. Not on the app i'm building or anywhere on my screen. – driima Jul 09 '16 at 21:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116892/discussion-between-raduation-and-eternity). – raduation Jul 09 '16 at 21:05
  • 3
    This sounds like a Chrome bug, not a programming problem. – jib Jul 10 '16 at 21:20
  • @jib Is it worth submitting an issue to the Chrome team? I'm unsure as to whether or not getUserMedia is still being supported by them – driima Jul 15 '16 at 08:20
  • @Eternity absolutely it is supported. There's a misconception it was deprecated because the API surface was renamed to `navigator.mediaDevices.getUserMedia`. And then Chrome switched to requiring `https` at the same time. So, yes. – jib Jul 15 '16 at 12:26

0 Answers0