JavaScript MediaStream id Property

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

The read-only id property on a MediaStream is a 36-character unique identifier (GUID) for that stream object. Learn the MDN getUserMedia example, UUID-style format checks, storing streams in a Map by id, how stream.id differs from track.id, and a permission-free canvas.captureStream() demo—with five examples and try-it labs.

01

Kind

Instance property

02

Returns

String GUID

03

Read-only

no setter

04

Length

36 characters

05

Use case

Lookup key

06

Status

Baseline widely

Introduction

Every MediaStream object the browser creates gets its own id—a string you can read but never change. You receive streams from getUserMedia(), captureStream(), WebRTC, and similar APIs; each new stream carries a fresh id.

MDN describes id as a 36-character GUID (globally unique identifier). In practice it looks like a UUID with hyphens, for example f47ac10b-58cc-4372-a567-0e02b2c3d479. Use it to label streams in logs, store them in a Map, or tell two camera feeds apart in a multi-stream app.

💡
Beginner tip

id identifies the stream object, not the camera hardware. Two getUserMedia calls give two different ids even if they use the same physical webcam.

Understanding the id Property

A read-only instance property on MediaStream that holds the stream’s unique string identifier.

  • Type — string.
  • Read-only — you cannot assign to stream.id.
  • Length — 36 characters (MDN).
  • Format — GUID / UUID-style with hyphens.
  • Unique — each MediaStream instance gets its own id.
  • Typical read — right after getUserMedia() resolves.
  • Baseline Widely available on MDN (since September 2017).

📝 Syntax

Read id on any MediaStream object:

JavaScript
mediaStream.id

Return value

A string: the unique identifier for this MediaStream (36 characters per MDN).

Typical pattern (MDN idea)

JavaScript
const promise = navigator.mediaDevices.getUserMedia({
  audio: true,
  video: true,
});

promise.then((stream) => {
  console.log(stream.id);
});

⚡ Quick Reference

GoalCode / note
Read stream idstream.id
Check lengthstream.id.length === 36
Store by idstreams.set(stream.id, stream)
Log for debugconsole.log("stream", stream.id)
Read-onlyCannot assign to id
MDN statusBaseline Widely available (since September 2017)

🔍 At a Glance

Four facts to remember about MediaStream.id.

Type
string

GUID text

Access
read-only

No setter

Length
36

Characters

Baseline
widely

Since Sep 2017

Examples Gallery

Examples follow MDN MediaStream.id. Labs use getUserMedia (secure context + permission) or canvas.captureStream() when no camera is needed.

📚 Getting Started

MDN pattern: log stream.id after getUserMedia().

Example 1 — MDN: Log stream.id After getUserMedia

Every successful capture returns a stream with its own id string.

JavaScript
navigator.mediaDevices
  .getUserMedia({ audio: true, video: true })
  .then((stream) => {
    console.log(stream.id);
  });
Try It Yourself

How It Works

MDN: id is assigned when the MediaStream is created—read it anytime on that object.

Example 2 — Check the 36-Character UUID Shape

Validate length and hyphen pattern for learning and debugging.

JavaScript
const canvas = document.createElement("canvas");
const stream = canvas.captureStream();
const uuidLike = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

console.log(stream.id.length);
console.log(uuidLike.test(stream.id));
Try It Yourself

How It Works

MDN specifies 36 characters; browsers typically use lowercase hex UUID formatting.

📈 Storage & Comparison

Map streams by id and compare with track ids.

Example 3 — Store Streams in a Map by id

Handy when you manage multiple live feeds in one app.

JavaScript
const streamsById = new Map();
const canvas = document.createElement("canvas");

function registerStream(stream) {
  streamsById.set(stream.id, stream);
  return stream.id;
}

const a = canvas.captureStream();
const b = canvas.captureStream();

registerStream(a);
registerStream(b);

console.log(streamsById.size);
console.log(a.id === b.id);
Try It Yourself

How It Works

Each stream’s id is a stable key until you delete the entry from your Map.

Example 4 — stream.id vs track.id

The stream and its tracks each have their own identifier.

JavaScript
const stream = canvas.captureStream();
const track = stream.getVideoTracks()[0];

console.log("stream:", stream.id);
console.log("track:", track.id);
console.log(stream.id === track.id);
Try It Yourself

How It Works

Do not use stream.id when you need a specific track—read track.id on each MediaStreamTrack.

Example 5 — Two captureStream() Calls, Two Different ids

No camera permission needed—each call creates a new stream id.

JavaScript
const canvas = document.createElement("canvas");
const first = canvas.captureStream();
const second = canvas.captureStream();

console.log(first.id);
console.log(second.id);
console.log(first.id === second.id);
Try It Yourself

How It Works

A new MediaStream object always gets a new id, even from the same canvas element.

🚀 Common Use Cases

  • Log stream.id when debugging WebRTC or getUserMedia issues.
  • Key a Map or object that holds multiple active streams.
  • Match UI labels to the correct stream in multi-camera layouts.
  • Verify you received a new stream after re-calling getUserMedia.
  • Distinguish stream id from track id in signaling or analytics payloads.

🔧 How It Works

1

Create a MediaStream

getUserMedia, captureStream, or WebRTC constructs a new MediaStream object.

Context
2

Browser assigns id

A 36-character GUID string is generated and stored on the object.

Identity
3

Read stream.id

Returns the same string for the lifetime of that object—read-only.

Property
4

Use as lookup key

Store, log, or compare ids. New stream objects always get new ids.

📝 Notes

  • MDN: Baseline Widely available (since September 2017) — no Deprecated / Experimental / Non-standard banner.
  • Read-only — you cannot set stream.id to a custom value.
  • Not HTML id — unrelated to DOM element id attributes.
  • Per object — stopping tracks does not change stream.id.
  • Related learning: MediaStream.active, navigator.mediaDevices, getUserMedia(), MediaStreamTrack.id.

Universal Browser Support

MediaStream.id is marked Baseline Widely available on MDN (since September 2017). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

MediaStream.id

Read-only 36-character GUID string—unique per MediaStream object.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer No MediaStream.id
Not supported
MediaStream.id Excellent

Bottom line: Read stream.id to identify, log, or index MediaStream objects in your app.

Conclusion

MediaStream.id is a read-only string—a 36-character GUID that uniquely identifies one MediaStream object. Read it after getUserMedia(), use it as a Map key, and remember that each track has its own separate id.

Continue with MediaStream.active, getUserMedia(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use stream.id as a key in Map or lookup tables
  • Log ids when debugging multi-stream WebRTC apps
  • Check id.length === 36 when validating stream objects
  • Read track.id when you need per-track identity
  • Pair with active for lifecycle checks

❌ Don’t

  • Try to assign stream.id = "my-stream"
  • Assume stream.id equals track.id
  • Confuse with HTML element.id
  • Expect the same id after creating a new MediaStream
  • Use id alone as a permanent user identity—it identifies objects, not people

Key Takeaways

Knowledge Unlocked

Five things to remember about id

Unique GUID string on every MediaStream.

5
Core concepts
⚙️02

Read-only

no setter

Access
⚠️03

Length

36 chars

Format
📄04

Unique

per stream

Identity
🎯05

Baseline

since Sep 2017

Status

❓ Frequently Asked Questions

A read-only string containing 36 characters. MDN describes it as a unique identifier (GUID) for that MediaStream object.
No. MDN marks MediaStream.id as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
No. id is read-only. The browser generates it when the MediaStream is created. You cannot set stream.id to your own value.
No. Each MediaStream has its own id, and each MediaStreamTrack inside it has a separate id. They are related objects but different identifiers.
Yes. Each MediaStream returned by getUserMedia or captureStream is a new object with its own unique id string.
It is a 36-character GUID-style string (UUID format with hyphens), for example 550e8400-e29b-41d4-a716-446655440000.
Did you know?

MDN’s id example is just console.log(stream.id) inside a getUserMedia then callback—one line to see the browser-assigned GUID for your stream.

Create a MediaStream

Learn the MediaStream() constructor—empty, from tracks, or from another stream.

constructor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful