Skip to content

Instantly share code, notes, and snippets.

@unixpickle
Created October 25, 2018 16:43
Show Gist options
  • Save unixpickle/31a9e959b1e765c4ab7cb4fee659e9f4 to your computer and use it in GitHub Desktop.
Save unixpickle/31a9e959b1e765c4ab7cb4fee659e9f4 to your computer and use it in GitHub Desktop.
getUserMedia() spoof
function fakeGetUserMedia(options) {
var canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 480;
var result = new Promise((resolve, reject) => {
setTimeout(() => {
var ctx = canvas.getContext('2d');
ctx.font = '100px sans-serif';
ctx.fillText('💩', 200, 200);
resolve(canvas.captureStream(30));
}, 100);
});
return result;
}
navigator.getUserMedia = fakeGetUserMedia;
navigator.webkitGetUserMedia = fakeGetUserMedia;
navigator.mediaDevices.getUserMedia = fakeGetUserMedia;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment