Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Screen capture with javascript mediaDevices api

what I am trying to achieve is add an option to my webApp that the users can screeshot the screen. I tried out some ready2use libraries like html2canvas and rasterizeHTML but I am experiensing problems with them. I found out a possible solution using the mediaDevices api, but there are several things that I want to change and not sure how. Here is my code:

navigator.mediaDevices.getDisplayMedia().then(stream => 
{
  // Grab frame from stream
  let track = stream.getVideoTracks()[0];
  let capture = new ImageCapture(track);
  let canvas = document.createElement('canvas');  
  capture.grabFrame().then(bitmap => 
  {
    track.stop();
      
    canvas.width = bitmap.width;
    canvas.height = bitmap.height;
    canvas.getContext('2d').drawImage(bitmap, 0, 0);
      
    let a = document.createElement("a");
    document.body.appendChild(a);

    a.href = canvas.toDataURL(`image/png`);
    a.download = "screenshot.png";

    a.click();
  });
})
.catch(e => console.log(e));

Using this piece of code I am getting the options to choose from my available screens and pick what to screenshot. I have 2 problems with this:

  1. The dialog that is poping has a button called share, I want to change it so it is saying screenshot. Is it possible to adjust the dialog and at least rename the primary button ?
  2. If I attach this code to a component inside my app - for example on button click, if I want to screenshot my current screen, the dialog for the screenshot is also visible in the image, but I don't want it. Is it possible to ignore the pop-up while doing the screenshot?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!