Firefox Tomorrow

web api instance method

BrowserCaptureMediaStreamTrack: clone() method

View on MDN ↗

Limited availabilitySecure context

The clone() method of the BrowserCaptureMediaStreamTrack interface returns a clone of the original BrowserCaptureMediaStreamTrack.

This method is functionally identical to clone(), except that it handles cases where cropping or restriction have been applied to the track. The returned clone is identical to the original BrowserCaptureMediaStreamTrack, but with any cropping or restriction removed.

[!NOTE] In Chromium, if a track has clones, its cropTo() and restrictTo() methods will reject (see Chrome issue 41482026).

Syntax

clone()

Parameters

None.

Return value

A BrowserCaptureMediaStreamTrack instance.

Examples

// Options for getDisplayMedia()
const displayMediaOptions = {
  preferCurrentTab: true,
};

// Create crop target from DOM element
const demoElem = document.querySelector("#demo");
const cropTarget = await CropTarget.fromElement(demoElem);

// Capture video stream from user's webcam and isolate video track
const stream =
  await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
const [track] = stream.getVideoTracks();

// Crop video track
await track.cropTo(cropTarget);

// Create uncropped clone of the track
const clonedTrack = track.clone();

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also