MediaStream: addtrack event

The addtrack event is fired when a new MediaStreamTrack object has been added to a MediaStream.

This event is not cancelable and does not bubble.


Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener("addtrack", (event) => {});

onaddtrack = (event) => {};

Event type

Event properties

Also inherits properties from its parent interface, Event.

MediaStreamTrackEvent.track Read only

A MediaStreamTrack object representing the track which was added to the stream.


Using addEventListener():

const stream = new MediaStream();

stream.addEventListener("addtrack", (event) => {
  console.log(`New ${event.track.kind} track added`);

Using the onaddtrack event handler property:

const stream = new MediaStream();

stream.onaddtrack = (event) => {
  console.log(`New ${event.track.kind} track added`);


Media Capture and Streams
# event-mediastream-addtrack

Browser compatibility

BCD tables only load in the browser

See also