navigator.getUserMedia() was the original way to open the webcam or mic from JavaScript. Learn its callback syntax, constraints, why it is deprecated, and how to migrate to mediaDevices.getUserMedia() with five examples and try-it labs.
01
Kind
Method
02
Returns
undefined (callbacks)
03
Status
Deprecated
04
Context
Secure (HTTPS)
05
Modern API
mediaDevices.getUserMedia
06
Delivers
MediaStream
Fundamentals
Introduction
Video calls, selfie filters, and voice notes all need permission to use the camera or microphone. Early browsers exposed that as navigator.getUserMedia(constraints, success, error).
Today every modern browser prefers navigator.mediaDevices.getUserMedia(). The old method still appears in tutorials and legacy code, so beginners should recognize it — and know what to write instead.
💡
One-line migration
Replace callback navigator.getUserMedia(...) with await navigator.mediaDevices.getUserMedia(constraints), then video.srcObject = stream.
Concept
Understanding the getUserMedia() Method
Three arguments — constraints, successCallback, errorCallback.
No return value — results arrive only through callbacks.
Success gets a MediaStream — assign it to video.srcObject (or an audio element).
Error gets a DOMException-like object — check err.name (for example NotAllowedError, NotFoundError).
User may not choose — if the prompt is ignored, neither callback may run.
Secure context — HTTPS / localhost in supporting browsers.
Four facts to remember about navigator.getUserMedia().
Style
callbacks
Not a Promise
Status
Deprecated
Use mediaDevices
Context
HTTPS
Secure required
Result
MediaStream
Camera / mic tracks
Compare
📋 Legacy vs Modern getUserMedia
navigator.getUserMedia
mediaDevices.getUserMedia
Status
Deprecated
Current standard
Result style
Callbacks
Promise (async/await)
Vendor prefixes
Often needed in old code
Not required
New projects
Avoid
Prefer
Hands-On
Examples Gallery
Examples show detection, legacy callbacks (for reading old code), and the modern Promise API you should ship. Try It Yourself may prompt for camera / mic permission on HTTPS or localhost.
📚 Getting Started
Detect which APIs exist before requesting media.
Example 1 — Feature Detection
Compare the deprecated Navigator method with the modern MediaDevices method.
navigator.getUserMedia() is deprecated. Modern browsers expose navigator.mediaDevices.getUserMedia() instead. Some engines still keep a legacy alias for compatibility, but new apps should feature-detect MediaDevices and use the Promise API on HTTPS.
✓ Deprecated · Use mediaDevices
Navigator.getUserMedia()
Legacy callback camera/mic API — migrate to mediaDevices.getUserMedia().
LegacyDeprecated
Google ChromePrefer mediaDevices; legacy may remain as alias
Legacy
Microsoft EdgePrefer mediaDevices (Chromium)
Legacy
OperaPrefer mediaDevices
Legacy
Mozilla FirefoxPrefer mediaDevices; old moz prefix era ended
Legacy
Apple SafariPrefer mediaDevices on HTTPS
Legacy
Internet ExplorerNo modern MediaDevices path
Unavailable
getUserMedia() (Navigator)Deprecated
Bottom line: Detect mediaDevices.getUserMedia first, request media on a secure page, attach MediaStream to video.srcObject, and stop tracks when done.
Wrap Up
Conclusion
navigator.getUserMedia() taught the web how to open cameras and microphones, but its callback style is deprecated. Learn it to read old samples, then ship navigator.mediaDevices.getUserMedia() with clear permission UX and track cleanup.
Explain why you need camera / mic before prompting
Handle NotAllowedError and NotFoundError
Stop tracks when the preview closes
❌ Don’t
Start new features on navigator.getUserMedia
Rely on webkit / moz prefixes forever
Leave the camera running after the UI closes
Assume devices exist without checking errors
Request both mic and camera if you only need one
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about getUserMedia()
Deprecated callback API — migrate to mediaDevices for camera and mic.
5
Core concepts
📹01
Legacy
callback API
Navigator
⚠02
Status
Deprecated
Avoid
✨03
Modern
mediaDevices
Promise
🔒04
Context
HTTPS required
Secure
🛑05
Cleanup
track.stop()
Always
❓ Frequently Asked Questions
It is the old callback API that asks for permission to use the camera and/or microphone and delivers a MediaStream to a success callback, or an error object to an error callback.
No. MDN marks it Deprecated. Use navigator.mediaDevices.getUserMedia(), which returns a Promise and is the supported modern API.
navigator.mediaDevices.getUserMedia(constraints). Await the Promise, assign stream to video.srcObject, and stop tracks when finished.
Yes in supporting browsers: getUserMedia is available only in secure contexts (HTTPS or localhost).
An object describing which media you want, such as { audio: true, video: true } or more detailed video size settings like { video: { width: 1280, height: 720 } }.
On the legacy API, neither callback may run until the user chooses Allow or Block. Always design UI that waits for a decision and offers a clear retry.
Did you know?
Early demos used webkitGetUserMedia and mozGetUserMedia. Those prefixes are historical — today’s standard path is navigator.mediaDevices.getUserMedia() with no vendor prefix.