Skip to content

Instantly share code, notes, and snippets.

@leonardokl
Created June 3, 2017 18:05
Show Gist options
  • Save leonardokl/40ecfd90518ebfa37d590125ecf7b448 to your computer and use it in GitHub Desktop.
Save leonardokl/40ecfd90518ebfa37d590125ecf7b448 to your computer and use it in GitHub Desktop.
Display Webcam Stream
<!DOCTYPE html>
<html>
<head>
<title>Display Webcam Stream</title>
<style>
body {
margin: 0;
}
#webcam {
position: absolute;
width: 100%;
height: 100%;
background-color: #111;
}
</style>
</head>
<body>
<video autoplay="true" id="webcam">
<script>
let $video = document.querySelector("#webcam")
navigator.mediaDevices.getUserMedia({ video: { facingMode: "user" } })
.then(window.URL.createObjectURL)
.then(url => $video.src = url)
.catch(console.error)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment