1. Web
  2. Web APIs
  3. RestrictionTarget

RestrictionTarget

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.

The RestrictionTarget interface of the Screen Capture API provides a static method, fromElement(), which returns a RestrictionTarget instance that can be used to restrict a captured video track to a specified DOM element.

Static methods

fromElement()

Returns a RestrictionTarget instance that can be used to restrict a captured video track to a specified DOM element (plus its descendants).

Examples

js
// 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

Specification
Element Capture
# dom-restrictiontarget

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /