This <usermedia> HTML element demo exercises the new capability element that shipped in Chrome 151. You put the tag on the page, the browser draws the button, the user clicks it, and your page gets a MediaStream — with no getUserMedia() call of your own.
It covers the full shipped surface of HTMLUserMediaElement, plus the sibling <camera> and <microphone> elements:
stream,errorandcancelevents (and theironstream/onerror/oncancelhandlers)streamanderrorpropertiessetConstraints()and the constraint filter Chrome runs it through- Declarative constraints via a nested
<script type="permissionconstraints"> - The
:grantedpseudo-class and the enforced CSS rulebook - The browser-supplied,
lang-driven button label <camera>and<microphone>with their flatMediaTrackConstraintSetandtrackevent- Legacy
typemode:isValid,invalidReason,permissionStatus,isTypeSupported(),promptaction,promptdismiss,validationstatuschange - Permissions policy and cross-origin rules in iframes
- A
getUserMedia()fallback for browsers that don't know the tag
- Serve the folder over HTTPS or
localhost— the element needs a secure context, and the iframe demos won't load overfile://. Anything works:python3 -m http.server,npx serve, etc. - Open it in Chrome 151 or later. Chrome 153+ for the
<camera>and<microphone>sections. - Click the browser-drawn button in section 1 and allow camera and microphone.
- Before clicking, try the constraints lab in section 2 — it shows which of your constraints Chrome keeps and which it silently discards.
- Break the element on purpose in the styling playground in section 4 and watch Chrome disable it.
- Watch the event & error log at the bottom the whole time.
- Live
stream/error/cancelhandling with a video preview, input level meter and per-track table (settings, capabilities, constraints,readyState,enabled,muted) - A constraint sanitizer that mirrors Chromium's own
SanitizeTrackConstraints()— paste any constraint dictionary and see each key marked kept or dropped, with the reason - A styling playground with a live CSS editor, nine one-click violation presets, an author-value vs. computed-value table, and a validity predictor running Chrome's real thresholds (3:1 contrast, opaque colors,
small–xxx-largefont size, alloweddisplayvalues, occlusion) - Trusted-activation probes:
element.click(),element.focus()and a syntheticMouseEvent, so you can see what an untrusted activation does - Two iframes side by side, one with
allow="camera; microphone"and one withallow="camera 'none'; microphone 'none'", both reporting back into the main log - A code generator that emits working markup, CSS and JS for whatever constraints and styling you configured
- Environment & support panel: element and interface detection, secure context, permissions policy, live Permissions API state, Chrome version
- Progressive enhancement throughout — every element carries a nested
<button>wired togetUserMedia(), so the page still works in Firefox and Safari
The page logs every stream, error and cancel event from every element on the page, every MediaStreamTrack state change (mute, unmute, ended), every Permissions API change, every style validation result, every message posted back from the iframes, and every uncaught page error — each with the elapsed time since page load. The log can be filtered by level and copied to the clipboard, which makes it useful when reporting a browser bug. Chrome's own complaints about your CSS go to the DevTools Issues panel rather than here.
- Chrome 151+ on Windows, macOS, Linux, ChromeOS and Android —
<usermedia> - Chrome 153+ —
<camera>and<microphone>. Earlier builds can enable them with theCameraAndMicrophoneElementsflag underchrome://flags/#enable-experimental-web-platform-features - Secure contexts only: HTTPS, or
localhost/127.0.0.1 - Everywhere else the tag is an
HTMLUnknownElement, the nested<button>renders, and the demo falls back togetUserMedia()
- No video-only or audio-only stream from
<usermedia>. The constraint filter always emits both an audio and a video entry, soaudio: falseis discarded and the camera light comes on even if you only wanted a microphone. Use<camera>or<microphone>instead setConstraints()is one-shot. Chromium returns early on every call after the first — no warning, no exception, no console message. Chrome's announcement post describes it as a way to "update" preferences, which it isn't- Wrapped constraints are dropped silently. Only bare values survive:
{ width: 1280 }is kept,{ width: { ideal: 1280 } }is discarded key and all, as areexact,min,maxandadvanced. This is deliberate — it stops the element ever failing with anOverconstrainedError— but it makes reliable device selection and resolution pinning hard. Only 16 properties are on the allowlist at all; section 2 of the demo lists them - In a cross-origin iframe the element is invalid unless the framed document also serves a Content-Security-Policy containing
frame-ancestors— a requirementgetUserMedia()does not have, and one that quietly breaks embedded widgets - When the element is invalid — blocked by permissions policy, occluded, clipped, badly styled, or freshly attached — clicks produce nothing at all. No event, no exception, so there is no way for your code to notice. Standard mode has no
isValid; that only exists in the deprecatedtypelegacy mode - No
autostartattribute in the shipped element. It is described in the explainer but is not in Chrome 151, so there is no way to resume a previously granted stream without a click - No declarative way to connect the element to a
<video>. You still need JavaScript to setsrcObject - A stream starts live. There is no way to acquire it with tracks disabled, so the hardware indicator lights up the moment permission is granted
- The element is not focusable from script and is skipped by
autofocuswithout user activation, so keyboard-first flows need care <script type="permissionconstraints">for declarative constraints is not documented by Chrome. The demo probes it at runtime and reports whether it actually did anything in your browser- Not available in Android WebView, which rules out a large slice of in-app browsers
- Chrome-only for now. Firefox has the proposal under consideration and WebKit has not given a position
- Introducing the <usermedia> HTML element — Chrome for Developers
- Media Capture Elements explainer —
<camera>,<microphone>,<usermedia> - Specification — Media Capture and Streams Extensions
- <usermedia> on Chrome Platform Status
- Web Platform Tests for the element
- Introducing the <geolocation> HTML element — the first capability element
- The original <permission> element origin trial (PEPC) — where the CSS rulebook comes from
- Getting Started With getUserMedia