new MediaStream() returns a new MediaStream — a collection of MediaStreamTrack objects (audio, video, and more). Per MDN, you can create an empty stream, copy tracks from another stream, or pass an array of tracks.
Pass the required arguments shown below. Tracks may be shared across streams — know ownership before you stop them.
Syntax
Create a MediaStream. Start with this line.
JavaScript
new MediaStream() / (stream) / (tracks)
Call
What it does
new MediaStream() / (stream) / (tracks)
Primary signature.
Built into the browser. Call new MediaStream(...) — no import required.
Library declarations
JavaScript
new MediaStream() / (stream) / (tracks)
Parameters
Parameter
Description
(none)
Optional. Empty stream with a new id
tracks
Optional. Array of MediaStreamTrack objects
Return Value
Return Value
Description
*
A new MediaStream
JavaScript Examples
Example 1 — Empty MediaStream
Create a stream with no tracks and inspect its basics.
Start with a source stream. Canvas capture supplies one video track.
Pass the stream.new MediaStream(original) adds those tracks to a new stream.
IDs differ. Each MediaStream gets its own id.
Tracks are shared. Stopping the track on one stream affects the other.
Compatibility
Browser Support
The MediaStream() constructor is Baseline Widely available (MDN: since September 2017). It is part of the Media Capture and Streams specification. It is a browser Web API — not available in Node.js, Bun, or Deno.
✓ Baseline · Widely available
MediaStream()
Supported across modern Chrome, Firefox, Safari, and Edge for creating and composing media streams.
98%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
MediaStream()Excellent
Bottom line: Browser only — not a Node.js API. Safe for production web apps. Feature-detect with typeof MediaStream === "function" if you must support very old environments.
Frequently Asked Questions
new MediaStream() returns a new MediaStream — a collection of MediaStreamTrack objects. With no arguments the stream is empty; you can also pass another stream or an array of tracks.
No. MDN marks the MediaStream() constructor as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
getUserMedia() asks for camera/microphone permission and returns a live device stream. new MediaStream() builds or reassembles streams in code without opening devices — useful for composition and tests.
No. new MediaStream(otherStream) adds the same track references. Tracks are shared; stopping a track affects every stream that contains it.
new MediaStream(stream) shares the original track objects. stream.clone() returns a new stream with a unique id and cloned tracks (not the same track references).
Yes. Even new MediaStream() with no tracks gets a browser-assigned id string.