JavaScript MediaStream id Property

Beginner
5 min read
Updated: Nov 2026
5 examples
Property

Definition

MediaStream.id is a read-only string of 36 characters — a unique identifier (GUID) for that stream object (MDN).

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use stream.id. Start with this line.

JavaScript
stream.id
CallWhat it does
stream.idPrimary signature.

Built into the browser. Read stream.id on a MediaStream — no import required.

Library declarations
JavaScript
stream.id

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*36-character unique GUID string

JavaScript Examples

Example 1 — Empty Stream Still Has an id

Even a stream with no tracks gets a unique GUID.

JavaScript
const stream = new MediaStream();

console.log(stream.getTracks().length); // 0
console.log(stream.id.length);          // 36
console.log(stream.id);                 // e.g. "…-…-…-…-…"
Try It Yourself

How It Works

  1. Create an empty stream. No tracks required.
  2. Browser still assigns an id. Object identity, not track count.
  3. Length is 36. GUID format (MDN).
  4. No permissions needed. Safe classroom demo.

Example 2 — UUID Format Check

Confirm length and hyphenated UUID pattern on a canvas stream.

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);           // 36
console.log(uuidLike.test(stream.id));   // true
console.log(stream.id);
Try It Yourself

How It Works

  1. captureStream() creates a stream. No camera prompt.
  2. Check length 36. Matches MDN’s GUID description.
  3. Regex checks UUID shape. Eight-four-four-four-twelve hex groups.
  4. Log the raw id. Useful when debugging WebRTC apps.

Example 3 — getUserMedia (MDN)

Log the id of a camera/microphone stream.

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

How It Works

  1. Request A/V. Needs HTTPS or localhost.
  2. Promise resolves with a stream. New object each call.
  3. Read stream.id. MDN’s basic example.
  4. Use for logging / keys. Not for display to end users usually.

Example 4 — Store Streams in a Map

Key a registry by stream.id — each stream stays unique.

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

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

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

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

How It Works

  1. Create two streams. Same canvas, different stream objects.
  2. Register by id. Map keys must be unique.
  3. Size is 2. Different GUIDs.
  4. Ids are not equal. Each stream owns its id (MDN uniqueness).

Example 5 — stream.id vs track.id

The stream and its tracks have separate identifiers.

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

console.log(stream.id);
console.log(track.id);
console.log(stream.id === track.id); // false
Try It Yourself

How It Works

  1. Stream has an id. Identifies the container.
  2. Track has its own id. Identifies the media track.
  3. They are not equal. Different objects.
  4. Pick the right one. Stream registry vs track registry.

Browser Support

MediaStream.id is Baseline Widely available (MDN, since September 2017). Safe for modern media apps.

✓ Baseline · Widely available

MediaStream.id

Supported across Chrome, Firefox, Safari, Edge, and Opera. Read-only 36-character GUID string for each MediaStream.

97% Browser support
Google Chrome id · full support
Full support
Microsoft Edge id · Chromium
Full support
Apple Safari id · full support
Full support
Mozilla Firefox id · full support
Full support
Opera id · full support
Full support
Internet Explorer MediaStream · not supported
No support
MediaStream.id Excellent

Bottom line: Use freely as a unique key. Prefer canvas.captureStream for demos without camera permission.

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 identify different objects.
Yes. Each MediaStream returned by getUserMedia or captureStream is a new object with its own unique id string.
A 36-character GUID-style string (UUID format with hyphens), for example 550e8400-e29b-41d4-a716-446655440000.

Next: MediaStream Constructor

Learn how to create a MediaStream with new MediaStream().

constructor tutorial →

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.

10 people found this page helpful