MediaStream.addTrack(track) adds a MediaStreamTrack to the stream. Per MDN, if that track is already in the stream, the call does nothing. It returns undefined.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call stream.addTrack. Start with this line.
JavaScript
mediaStream.addTrack(track)
Call
What it does
mediaStream.addTrack(track)
Primary signature.
stream.addTrack(...)
Call with the arguments your case needs.
Built into the browser. Call addTrack(...) on a MediaStream — no import required.
Create two sources. Each canvas capture yields its own track.
Start empty.composed begins with no tracks.
Add both. Different track objects → both are accepted.
Result.getTracks().length is 2.
Compatibility
Browser Support
MediaStream.addTrack() 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.addTrack()
Supported across modern Chrome, Firefox, Safari, and Edge for 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
addTrack()Excellent
Bottom line: Browser only — not a Node.js API. Safe for production. Prefer new MediaStream(tracks) when you already have the full track list; use addTrack when tracks arrive over time.
Frequently Asked Questions
addTrack(track) adds a MediaStreamTrack to the stream. It returns undefined. Use getTracks() afterward to inspect the stream.
No. MDN marks MediaStream.addTrack() as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
If the track is already in the stream’s track set, addTrack() has no effect — the track is not added again.
new MediaStream([track]) builds a stream in one step. addTrack() lets you start with new MediaStream() and add tracks over time.
Usually yes when you add a live track. An empty stream is inactive until a live track is present.
Yes. Adding a track that was not already in the set typically fires the addtrack event on the stream.