RestrictionTarget

Khả dụng hạn chế

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.

Giao diện RestrictionTarget của Screen Capture API cung cấp phương thức tĩnh fromElement(), trả về một phiên bản RestrictionTarget có thể được sử dụng để giới hạn track video bị capture vào một phần tử DOM cụ thể.

Phương thức tĩnh

fromElement() Thử nghiệm

Trả về phiên bản RestrictionTarget có thể được sử dụng để giới hạn track video bị capture vào một phần tử DOM cụ thể (cùng với các phần tử con của nó).

Ví dụ

js
// Tùy chọn cho getDisplayMedia()
const displayMediaOptions = {
  preferCurrentTab: true,
};

// Tạo restriction target từ phần tử DOM
const demoElem = document.querySelector("#demo");
const restrictionTarget = await RestrictionTarget.fromElement(demoElem);

// Capture luồng video từ webcam của người dùng và tách track video
const stream =
  await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
const [track] = stream.getVideoTracks();

// Giới hạn track video
await track.restrictTo(restrictionTarget);

// Phát luồng bị giới hạn trong phần tử <video>
videoElem.srcObject = stream;

Xem Using the Element Capture and Region Capture APIs để biết ví dụ mã trong ngữ cảnh.

Thông số kỹ thuật

Thông số kỹ thuật
Element Capture
# dom-restrictiontarget

Tương thích trình duyệt

Xem thêm