Screen Capture API
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 BrowserCaptureMediaStreamTrack.cropTo and BrowserCaptureMediaStreamTrack.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
Browser compatibility
See also
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
