OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Function to take the screenshot of the current screen. | 6 * Function to take the screenshot of the current screen. |
7 * @param {function(HTMLCanvasElement)} callback Callback for returning the | 7 * @param {function(HTMLCanvasElement)} callback Callback for returning the |
8 * canvas with the screenshot on it. | 8 * canvas with the screenshot on it. |
9 */ | 9 */ |
10 function takeScreenshot(callback) { | 10 function takeScreenshot(callback) { |
(...skipping 12 matching lines...) Expand all Loading... |
23 video.src = ''; | 23 video.src = ''; |
24 | 24 |
25 screenshotStream.getVideoTracks()[0].stop(); | 25 screenshotStream.getVideoTracks()[0].stop(); |
26 screenshotStream = null; | 26 screenshotStream = null; |
27 | 27 |
28 callback(canvas); | 28 callback(canvas); |
29 } | 29 } |
30 }, false); | 30 }, false); |
31 | 31 |
32 navigator.webkitGetUserMedia( | 32 navigator.webkitGetUserMedia( |
33 { | 33 { |
34 video: { | 34 video: { |
35 mandatory: { | 35 mandatory: |
36 chromeMediaSource: 'screen', | 36 {chromeMediaSource: 'screen', maxWidth: 4096, maxHeight: 2560} |
37 maxWidth: 4096, | |
38 maxHeight: 2560 | |
39 } | 37 } |
40 } | 38 }, |
41 }, | 39 function(stream) { |
42 function(stream) { | 40 if (stream) { |
43 if (stream) { | 41 screenshotStream = stream; |
44 screenshotStream = stream; | 42 video.src = window.URL.createObjectURL(screenshotStream); |
45 video.src = window.URL.createObjectURL(screenshotStream); | 43 video.play(); |
46 video.play(); | 44 } |
47 } | 45 }, |
48 }, | 46 function(err) { |
49 function(err) { | 47 console.error( |
50 console.error('takeScreenshot failed: ' + | 48 'takeScreenshot failed: ' + err.name + '; ' + err.message + '; ' + |
51 err.name + '; ' + err.message + '; ' + err.constraintName); | 49 err.constraintName); |
52 } | 50 }); |
53 ); | |
54 } | 51 } |
OLD | NEW |