Screen Capture API
The RestrictionTarget interface of the Screen Capture API provides a static method, RestrictionTarget.fromElement_static, which returns a RestrictionTarget instance that can be used to restrict a captured video track to a specified DOM element.
Static methods
- RestrictionTarget.fromElement_static
- : Returns a
RestrictionTargetinstance that can be used to restrict a captured video track to a specified DOM element (plus its descendants).
- : Returns a
Examples
// Options for getDisplayMedia()
const displayMediaOptions = {
preferCurrentTab: true,
};
// Create restriction target from DOM element
const demoElem = document.querySelector("#demo");
const restrictionTarget = await RestrictionTarget.fromElement(demoElem);
// Capture video stream from user's webcam and isolate video track
const stream =
await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
const [track] = stream.getVideoTracks();
// Restrict video track
await track.restrictTo(restrictionTarget);
// Broadcast restricted stream in <video> element
videoElem.srcObject = stream;
See Using the Element Capture and Region Capture APIs for in-context example code.
Specifications
Browser compatibility
See also
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
