BrowserCaptureMediaStreamTrack: clone() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The clone()
method of the BrowserCaptureMediaStreamTrack
interface returns a clone of the original BrowserCaptureMediaStreamTrack
.
This method is functionally identical to MediaStreamTrack.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
Specification |
---|
Region Capture # dom-browsercapturemediastreamtrack-clone |
Browser compatibility
BCD tables only load in the browser