MediaStream.getTrackById(id) returns the oneMediaStreamTrack whose id matches the string you pass. Per MDN, if no track matches, the method returns null.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call stream.getTrackById. Start with this line.
JavaScript
mediaStream.getTrackById(id)
Call
What it does
mediaStream.getTrackById(id)
Primary signature.
stream.getTrackById(...)
Call with the arguments your case needs.
Built into the browser. Call getTrackById(...) on a MediaStream — no import required.
Save the id. You may not keep the track object itself.
Look it up.getTrackById(id).
Null-check. Only mute when a track was found.
Set enabled = false. Soft mute; look up again to confirm.
Compatibility
Browser Support
MediaStream.getTrackById() 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.getTrackById()
Supported across modern Chrome, Firefox, Safari, and Edge for looking up tracks by id.
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
getTrackById()Excellent
Bottom line: Browser only — not a Node.js API. Safe for production. Use it when you have a stored track id and need that one track back.
Frequently Asked Questions
A MediaStreamTrack whose id matches the string you pass. If no track in the stream has that id, it returns null.
No. MDN marks MediaStream.getTrackById() as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
One string argument: the track id to look up — getTrackById(id).
Each MediaStreamTrack has a read-only id string generated by the browser. Save it when you first get the stream if you need to look the track up later.
getTracks() returns every track as an array. getTrackById(id) returns one matching track, or null if none match.
No. MDN says the return value is null when no track matches — it does not throw.