Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

getdisplaymedia screenshot

courtesy of @BobbyTables on GitHub

<canvas id="canvas"></canvas>

// Request media
navigator.mediaDevices.getDisplayMedia().then(stream => 
{
  // Grab frame from stream
  let track = stream.getVideoTracks()[0];
  let capture = new ImageCapture(track);
  capture.grabFrame().then(bitmap => 
  {
    // Stop sharing
    track.stop();
      
    // Draw the bitmap to canvas
    canvas.width = bitmap.width;
    canvas.height = bitmap.height;
    canvas.getContext('2d').drawImage(bitmap, 0, 0);
      
    // Grab blob from canvas
    canvas.toBlob(blob => {
        // Do things with blob here
      blob.name = `screenshot-${new Date().getTime()}`;
      // copy to clipboard
      let data = [new ClipboardItem({ [blob.type]: blob })];
      navigator.clipboard.write(data);
      console.log('output blob:', blob);
    });
  });
})
.catch(e => console.log(e));
Comment

PREVIOUS NEXT
Code Example
Javascript :: vscode rest api extention POST method 
Javascript :: Mars Exploration problem in js 
Javascript :: javascript set input value by id 
Javascript :: convert a new date standard to a yyy-mm-dd format in javascript 
Javascript :: npm got 
Javascript :: js get selected option elemeng 
Javascript :: circular progress for react 
Javascript :: uppercase in javascript 
Javascript :: oneerror javascript image 
Javascript :: express req get json 
Javascript :: object flatten js 
Javascript :: node js run for loop asynchronously 
Javascript :: checkbox default value and checked value get in jquery 
Javascript :: react native create apk 
Javascript :: user input in js 
Javascript :: react click outside 
Javascript :: descending order in objects in js 
Javascript :: get element by xpath 
Javascript :: react webpack.config.js example 
Javascript :: active navbar in page reactjs 
Javascript :: base64 to image nodejs 
Javascript :: react Refused to execute inline script because it violates the following Content Security Policy directive 
Javascript :: jquery get all inputs in form 
Javascript :: Find the stray number 
Javascript :: slice method in js 
Javascript :: how to add json file to mongodb 
Javascript :: how to run react builed version 
Javascript :: Converting file to base64 on Javascript client side 
Javascript :: how to iterate array in javascript 
Javascript :: redirect after print javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =