JavaScript MediaStream clone() Method

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

What You’ll Learn

The clone() method of MediaStream creates a duplicate stream with a new id and cloned MediaStreamTrack objects. Learn how that differs from new MediaStream(stream) (shared tracks), verify independent track objects, and when to clone for WebRTC or recording—with five examples and try-it labs.

01

Kind

Instance method

02

Returns

MediaStream

03

Params

none

04

Tracks

cloned copies

05

New id

unique GUID

06

Status

Baseline widely

Introduction

Sometimes you need a copy of a media stream—for example, to send the same camera feed to two peer connections without sharing one stream object. Call stream.clone() on any MediaStream from getUserMedia(), captureStream(), or your own composed stream.

MDN: the returned stream has a new unique id and contains clones of every track in the original. That is different from new MediaStream(original), which reuses the same track references.

💡
Beginner tip

clone() is like photocopying the whole playlist and each song file—not just pointing two playlists at the same files.

Understanding MediaStream.clone()

An instance method that duplicates the stream and its tracks without modifying the original.

  • Parameters — none.
  • Return value — a new MediaStream instance.
  • New id — the clone gets its own unique id string.
  • Cloned tracks — each track is a clone, not the same object reference.
  • Original unchanged — the source stream stays as it was.
  • Baseline Widely available on MDN (since September 2017).

📝 Syntax

JavaScript
clone()

Parameters

None.

Return value

A new MediaStream with a new unique id and cloned copies of every MediaStreamTrack from the original stream.

Typical pattern

JavaScript
const original = canvas.captureStream();
const copy = original.clone();

console.log(original.id === copy.id);
console.log(original.getTracks().length, copy.getTracks().length);

⚡ Quick Reference

GoalCode / note
Duplicate streamconst copy = stream.clone()
New idcopy.id !== stream.id
Cloned trackscopy.getTracks()[0] !== stream.getTracks()[0]
Same track countcopy.getTracks().length matches original
Share refs insteadnew MediaStream(stream)
MDN statusBaseline Widely available (since September 2017)

🔍 At a Glance

Four facts to remember about MediaStream.clone().

Returns
MediaStream

New object

Params
none

No arguments

Tracks
cloned

Not shared

Baseline
widely

Since Sep 2017

Examples Gallery

Examples follow MDN MediaStream: clone(). Labs use canvas.captureStream() so no camera permission is required.

📚 Getting Started

Call clone() and inspect the duplicate stream.

Example 1 — Basic stream.clone()

Duplicate a canvas stream and compare track counts.

JavaScript
const canvas = document.createElement("canvas");
const original = canvas.captureStream();
const copy = original.clone();

console.log(original.getTracks().length, copy.getTracks().length);
console.log(original === copy);
Try It Yourself

How It Works

MDN: clone() returns a new MediaStream object, not a reference to the same one.

Example 2 — Clone Gets a New id

Each stream object has its own unique GUID.

JavaScript
const canvas = document.createElement("canvas");
const original = canvas.captureStream();
const copy = original.clone();

console.log(original.id);
console.log(copy.id);
console.log(original.id === copy.id);
Try It Yourself

How It Works

See MediaStream.id—every new stream object gets a fresh id.

📈 Cloned vs Shared Tracks

Compare clone() with the constructor and track lifecycle.

Example 3 — Cloned Tracks Are Different Objects

MDN: the clone contains clones of every MediaStreamTrack.

JavaScript
const canvas = document.createElement("canvas");
const original = canvas.captureStream();
const copy = original.clone();

const origTrack = original.getVideoTracks()[0];
const copyTrack = copy.getVideoTracks()[0];

console.log(origTrack === copyTrack);
console.log(origTrack.id === copyTrack.id);
Try It Yourself

How It Works

Cloned tracks are new objects with their own ids—not the same reference as the original track.

Example 4 — clone() vs new MediaStream(stream)

Constructor shares tracks; clone() does not.

JavaScript
const canvas = document.createElement("canvas");
const original = canvas.captureStream();
const shared = new MediaStream(original);
const cloned = original.clone();

console.log(
  original.getTracks()[0] === shared.getTracks()[0],
  original.getTracks()[0] === cloned.getTracks()[0],
);
Try It Yourself

How It Works

Use clone() when you need independent track copies; use the constructor when sharing is intentional.

Example 5 — Stop Original Track; Clone May Stay Live

With cloned tracks, stopping the original track does not always stop the clone.

JavaScript
const canvas = document.createElement("canvas");
const original = canvas.captureStream();
const copy = original.clone();

original.getTracks()[0].stop();

console.log("original active:", original.active);
console.log("copy active:", copy.active);
Try It Yourself

How It Works

Independent cloned tracks can keep the copy stream active after the original track ends.

🚀 Common Use Cases

  • Send duplicate camera feeds to multiple WebRTC peer connections.
  • Branch a stream for recording while keeping the live preview running.
  • Snapshot stream state without sharing mutable track references.
  • Test pipelines with independent copies of the same capture.
  • Avoid accidental cross-stream stop() when consumers are separate.

🔧 How It Works

1

Call stream.clone()

No parameters—the browser duplicates the MediaStream object.

Method
2

Assign new id

The clone gets a fresh unique id string.

Identity
3

Clone each track

Every MediaStreamTrack in the source is cloned into the new stream.

Tracks
4

Return duplicate

Use the clone independently; original stream is unchanged.

📝 Notes

  • MDN: Baseline Widely available (since September 2017) — no Deprecated / Experimental / Non-standard banner.
  • Cloned tracks — not the same objects as in the original stream.
  • vs constructornew MediaStream(s) shares track refs; clone() does not.
  • Original intact — cloning does not remove or alter the source stream.
  • Related learning: MediaStream(), addTrack(), id, active.

Universal Browser Support

MediaStream.clone() 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.clone()

Duplicate a stream with a new id and cloned MediaStreamTrack objects.

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.clone
Not supported
MediaStream.clone() Excellent

Bottom line: Call stream.clone() when you need independent track copies and a new stream id.

Conclusion

MediaStream.clone() returns a duplicate stream with a new id and cloned copies of every track. Use it when you need independence from the original; use new MediaStream(stream) when you want to share track references instead.

Continue with addTrack(), id, active, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use clone() for independent WebRTC or recorder branches
  • Compare stream.id to confirm you have a new object
  • Stop cloned tracks when done to free resources
  • Prefer clone() over manual per-track track.clone() loops
  • Pair with active checks after cloning

❌ Don’t

  • Assume clone() shares track references like the constructor
  • Forget cloned tracks still consume media resources
  • Confuse clone() with shallow object copy in JavaScript
  • Expect the same id on original and clone
  • Clone ended streams expecting new live media without a source

Key Takeaways

Knowledge Unlocked

Five things to remember about clone()

Duplicate streams with independent tracks.

5
Core concepts
🔗02

New id

unique GUID

Identity
📦03

Tracks

cloned

Copies
📄04

vs ctor

shared refs

Compare
🎯05

Baseline

since Sep 2017

Status

❓ Frequently Asked Questions

clone() creates a duplicate MediaStream. The new stream has a new unique id and contains clones of every MediaStreamTrack from the original—not the same track objects.
No. MDN marks MediaStream.clone() as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
No. MDN documents clone() with no parameters. You call it on an existing MediaStream: stream.clone().
new MediaStream(other) shares the same track references. clone() returns a new stream whose tracks are independent clones—stopping a track on one stream does not necessarily end the cloned track on the other.
Yes. MDN says the new MediaStream has a new unique id. See MediaStream.id for the GUID format.
A new MediaStream instance with cloned tracks. The original stream is unchanged.
Did you know?

MDN says clone() gives you a stream with a new unique id and clones of every track—unlike new MediaStream(original), which reuses the exact same MediaStreamTrack objects.

List audio tracks

Learn getAudioTracks()—microphone tracks in any MediaStream.

getAudioTracks() →

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