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

120
Views
Why i cant use getUserMedia() in express html

When I run the html with the VScode live server, everything runs normally and the script inserted with get the media normally, but when I start serving this html through an express server, the navigator.mediaDevices.getUserMedia( ) doesn't work as it returns null//undefined, how to solve?

This is html code, runs normally with live reload and show the webcam:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>View Webcam</title>
  </head>
  <body>
    <style type="text/css">
      #container {
        margin: 0px auto;
        width: 500px;
        height: 375px;
        border: 10px #333 solid;
      }

      #videoElement {
        width: 500px;
        height: 375px;
        background-color: #777;
      }
    </style>
    <div id="container">
      <video autoplay="true" id="videoElement"></video>
    </div>
    <script type="text/javascript">
      var video = document.querySelector("#videoElement");
      navigator.getUserMedia =
        navigator.getUserMedia ||
        navigator.webkitGetUserMedia ||
        navigator.mozGetUserMedia ||
        navigator.msGetUserMedia ||
        navigator.oGetUserMedia;

      console.log(navigator.mediaDevices.getUserMedia)

      if (navigator.getUserMedia) {
        navigator.getUserMedia({ video: true }, handleVideo, videoError);
      }

      function handleVideo(stream) {
        video.srcObject = stream;
        video.play();
      }

      function videoError(e) {}
    </script>
  </body>
</html>

print from terminal

But, when i send this html with express, this happen(express code):

const express = require('express');
const path = require('path');

const app = express();
const port = process.env.PORT || 3000;
    
app.set('view engine', 'ejs')
app.use(express.static("public"));

app.get('/', (req, res) => {
  res.sendFile(path.resolve() + "/public/index.html")
})

app.listen(port, () => {
  console.log(`Running at port ${port}`)
})

Print of error on terminal

Any help?

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!