LoginSignup
12
9

More than 5 years have passed since last update.

Chromeでデスクトップキャプチャーするには

Last updated at Posted at 2014-05-28

2018/10追記

月日が流れ、 Screen Capture APIなるAPIが実装されたようです。
Qiitaでは以下の記事が分かり易そうでした。

事前準備

  • コマンドライン引数の「--enable-usermedia-screen-capturing」が必要
  • オレオレ証明書で良いのでhttpsでアクセスできるページのみ有効

OSXのコマンドライン引数

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --enable-usermedia-screen-capturing

Windows

C:\Users\foo\AppData\Local\Google\Chrome\Application\chrome.exe --enable-usermedia-screen-capturing

注意

すでにChromeが起動していると有効にならない

HTMLを用意

<html>
<meta charset="UTF-8">
<video id='world' width="256" height="256" autoplay></video>
<button onClick="start()">start</button>
<button onClick="stop()">stop</button>
<script>
var video = document.getElementById("world");
var localStream;

function start() {
    if (navigator.webkitGetUserMedia) {
        navigator.webkitGetUserMedia({
            audio: false,
            video: {
                mandatory: {
                    chromeMediaSource: 'screen',
                    minWidth: 1280,
                    maxWidth: 2560,
                    minHeight: 720,
                    maxHeight: 1440
                }
            }
        }, function (stream) {
            localStream = stream;
            var url = window.webkitURL.createObjectURL(stream);
            video.src = url;
            video.play();
        }, function (error) {});
    }
}

function stop() {
    if (navigator.webkitGetUserMedia) {
        localStream.stop();
    }
}
</script>
</html>

httpsでHTMLをアクセスできるようにする

koaでhttpsを使うなどを参考にw

じつは

この機能は将来的に廃止予定らしい

関連投稿

関連記事

12
9
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
9