JavaScript MediaStream active Property

Beginner
5 min read
Updated: Nov 2026
5 examples
Property

Definition

MediaStream.active is a read-only boolean: true if the stream is currently active, otherwise false (MDN). A stream is active when at least one of its tracks does not have readyState set to "ended".

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

Syntax

Use stream.active. Start with this line.

JavaScript
stream.active
CallWhat it does
stream.activePrimary signature.

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

Library declarations
JavaScript
stream.active

Parameters

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

Return Value

Return ValueDescription
*true if any track is not ended

JavaScript Examples

Example 1 — Empty MediaStream

A stream with no tracks is inactive.

JavaScript
const stream = new MediaStream();

console.log(stream.getTracks().length); // 0
console.log(stream.active);             // false
Try It Yourself

How It Works

  1. Construct an empty stream. No tracks attached.
  2. No live tracks. Nothing with readyState !== "ended".
  3. active is false. Matches MDN’s definition.
  4. No permissions needed. Safe classroom demo.

Example 2 — Canvas captureStream

Create a live track without the camera, then stop it.

JavaScript
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
ctx.fillRect(0, 0, 40, 40);

const stream = canvas.captureStream();
console.log(stream.active); // true

stream.getTracks().forEach((track) => track.stop());
console.log(stream.active); // false
Try It Yourself

How It Works

  1. captureStream() adds a video track. Usually live.
  2. active starts true. At least one non-ended track.
  3. Stop every track. Each ends.
  4. active becomes false. All tracks ended (MDN).

Example 3 — getUserMedia Button (MDN)

Disable Start while the camera/mic stream is active.

JavaScript
navigator.mediaDevices
  .getUserMedia({ audio: true, video: true })
  .then((stream) => {
    const startBtn = document.querySelector("#startBtn");
    startBtn.disabled = stream.active; // usually true
    console.log(stream.active);
  });
Try It Yourself

How It Works

  1. Request A/V. Needs HTTPS or localhost (secure context).
  2. Promise resolves with a stream. Tracks are live.
  3. Read stream.active. Typically true (MDN).
  4. Disable Start. UI reflects that media is already running.

Example 4 — Stop All Tracks

End every track so the stream becomes inactive.

JavaScript
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
  console.log("before:", stream.active); // true

  stream.getTracks().forEach((track) => track.stop());

  console.log("after:", stream.active); // false
});
Try It Yourself

How It Works

  1. Start with a live mic track. active is true.
  2. Stop each track. readyState becomes "ended".
  3. No non-ended tracks left. Stream is inactive (MDN).
  4. inactive may fire. Useful for cleanup UI.

Example 5 — Partial Stop Still Active

Stopping only video leaves audio live — active stays true.

JavaScript
navigator.mediaDevices
  .getUserMedia({ audio: true, video: true })
  .then((stream) => {
    const video = stream.getVideoTracks()[0];
    video.stop();

    console.log(video.readyState);   // "ended"
    console.log(stream.active);      // true (audio still live)
  });
Try It Yourself

How It Works

  1. Two tracks start live. Audio + video.
  2. Stop only video. That track ends.
  3. Audio remains. Still not "ended".
  4. active stays true. MDN: at least one non-ended track.

Browser Support

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

✓ Baseline · Widely available

MediaStream.active

Supported across Chrome, Firefox, Safari, Edge, and Opera. Read-only boolean: true while any track is not ended.

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

Bottom line: Use freely. Prefer canvas.captureStream for demos without camera permission; use getUserMedia on HTTPS/localhost.

Frequently Asked Questions

A read-only boolean. It is true when at least one MediaStreamTrack in the stream does not have readyState "ended". When every track has ended, active becomes false (MDN).
No. MDN marks MediaStream.active as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
Call stop() on every track in the stream. When all tracks end, active flips to false and the inactive event fires.
No. Each track has its own readyState ("live" or "ended"). active is a stream-level summary: true if any track is still not ended.
Immediately after a successful getUserMedia() call, the returned MediaStream usually has live audio and/or video tracks, so active is typically true.
The active property itself works on any MediaStream. Getting camera/mic streams via getUserMedia() requires a secure context (HTTPS or localhost).

Next: MediaStream.id

Learn how stream.id uniquely identifies a MediaStream.

id 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