v150 · Web APIs · Media
Capability Elements: <usermedia> MVP
Chrome 151 introduces the <usermedia> HTML element — a declarative, user-activated control for accessing camera and microphone streams. It addresses the problem of permission prompts being triggered without a recognisable user gesture, by letting the browser manage the permission request flow as part of a native element interaction.
concepts
-
Usermedia Demo
Shows the
<usermedia>element in action — click to activate it and observe how it requests camera/microphone access as part of the click interaction, then delivers the stream to a<video>element. -
Permission Flow
Compares the user experience of the old
getUserMedia()JavaScript approach (permission prompt fires at arbitrary JS call time) vs the new<usermedia>declarative approach where the browser controls the prompt as part of element activation. -
Attribute Explorer
Configure
setConstraints()for a mounted<usermedia>element and watch the generated native setup update in real time. Activate the native element when supported or its fallback content when not, then inspect the returnedMediaStream. -
Stream Capture Demo
End-to-end media capture demo using
<usermedia>. Activate the element or fallback controls, preview the stream, inspect track settings, enumerate devices after permission, and capture a still frame — all driven through the element'sstreamevent when native support is present. -
Fallback Experience
All five capability element states — idle, pending, granted, denied, and unsupported — simulated with real
getUserMedia()calls and appropriate fallback UI for each. Shows the contrast with the old JS approach that required manual state management and error handling. -
Constraint Configurator
Build the full constraint set for a
<usermedia>element interactively: video resolution (320×240–4K), frame rate (15–60 fps), facing mode (front/back), audio echo cancellation, noise suppression, auto gain, and sample rate. The mounted element receivessetConstraints()updates while the fallback button runs the equivalentgetUserMedia()call.
why it shipped
The getUserMedia() API requires JavaScript and can trigger permission prompts in response to any code path — including timers and callbacks — not just direct user gestures. Browsers try to restrict prompts to user-gesture contexts, but the definition of "user gesture" is complex and leaks through in practice. The <usermedia> element ties the permission request to an actual element activation (click, Enter key) that the browser fully controls, resulting in clearer UX and more predictable permission timing.
the API
<!-- Declarative camera/mic access -->
<usermedia id="capture">
<!-- Fallback for unsupported browsers -->
<button onclick="startCamera()">Start camera</button>
</usermedia>
<video id="preview" autoplay></video>
<script>
const um = document.getElementById('capture');
um.setConstraints({ video: {}, audio: {} });
// 'stream' fires when user activates the element and access succeeds
um.addEventListener('stream', () => {
const stream = um.stream; // MediaStream
document.getElementById('preview').srcObject = stream;
});
// 'error' fires if permission denied
um.addEventListener('error', event => {
console.error('Media access denied:', event.error);
});
</script>
references
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗