How the Webcam Test Opens and Reads the Camera
AnyTool Webcam Test runs entirely on the native MediaDevices API — navigator.mediaDevices.getUserMedia and enumerateDevices — with no library, CDN or upload. Pressing Start camera calls getUserMedia({ video, audio: false }) after checking window.isSecureContext, and the returned MediaStream is assigned to a muted, autoplay, playsInline <video> element so it previews live and is never recorded. The active video track’s getSettings() reports the negotiated width and height, frameRate, aspectRatio, deviceId and the human-readable track.label (camera name), and a separate requestAnimationFrame loop counts rendered frames to display the true on-screen fps alongside the value the driver reports. enumerateDevices() lists every videoinput — labels populate once permission is granted — to fill the camera dropdown; choosing another camera stops the current tracks and restarts getUserMedia with { deviceId: { exact } } for that device. A track ‘ended’ listener catches a camera that is unplugged or grabbed by another app mid-session.
- getUserMedia({ video }) → muted autoplay <video>; the feed is previewed, never recorded
- track.getSettings() → resolution, frame rate, aspect ratio, deviceId and label
- requestAnimationFrame loop measures the real on-screen fps, not just the reported rate
- enumerateDevices() populates a camera selector; switching restarts on the chosen deviceId
- Secure-context check + a track ‘ended’ listener for unplugged / in-use cameras
