The addtrack event fires on a MediaStream when a new MediaStreamTrack is added. Per MDN, it is a MediaStreamTrackEvent, is not cancelable, and does not bubble.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for addtrack. Start with this line.
JavaScript
stream.addEventListener("addtrack", handler)
Call
What it does
stream.addEventListener("addtrack", handler)
Primary signature.
Built into the browser. Listen with stream.addEventListener("addtrack", …) — no import required.
Library declarations
JavaScript
stream.addEventListener("addtrack", handler)
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Fires as a MediaStreamTrackEvent (listener receives the event).
JavaScript Examples
Example 1 — addEventListener("addtrack")
Listen first, then add a canvas video track.
JavaScript
const stream = new MediaStream();
const track = document.createElement("canvas")
.captureStream()
.getVideoTracks()[0];
stream.addEventListener("addtrack", (event) => {
console.log(`New ${event.track.kind} track added`);
});
stream.addTrack(track);
// New video track added
First add. Track enters the stream → event fires → count is 1.
Second add. Same track already present → addTrack no-op.
No second event.count stays 1.
Compatibility
Browser Support
The addtrack event 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 track-added notifications.
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
addtrackExcellent
Bottom line: Browser only — not a Node.js API. Safe for production. Prefer addEventListener("addtrack", …) when you may need more than one listener.
Frequently Asked Questions
When a new MediaStreamTrack is added to a MediaStream — for example after calling addTrack(track) when that track was not already in the stream.
No. MDN marks the addtrack event as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
A MediaStreamTrackEvent. It inherits from Event and exposes a read-only track property with the MediaStreamTrack that was added.
No. MDN says the event is not cancelable and does not bubble.
addTrack() adds a track to the stream. addtrack is the event that fires afterward — listen with addEventListener("addtrack", …) or onaddtrack.
removetrack fires when a track is removed from a MediaStream — for example after removeTrack(track). It is the counterpart to addtrack.