Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial review: Add documentation for Screen Capture extensions, element capture and region capture #36939

Merged
merged 18 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ A {{domxref("BrowserCaptureMediaStreamTrack")}} instance.
## Examples

```js
// Options for getDisplayMedia()
const displayMediaOptions = {
preferCurrentTab: true,
};

// Create crop target from DOM element
const demoElem = document.querySelector("#demo");
const cropTarget = await CropTarget.fromElement(demoArea);
const cropTarget = await CropTarget.fromElement(demoElem);

// Capture video stream from user's webcam and isolate video track
const stream =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ The promise will reject if:
### Basic cropping example

```js
// Options for getDisplayMedia()
const displayMediaOptions = {
preferCurrentTab: true,
};

// Create crop target from DOM element
const demoElem = document.querySelector("#demo");
const cropTarget = await CropTarget.fromElement(demoArea);
const cropTarget = await CropTarget.fromElement(demoElem);

// Capture video stream from user's webcam and isolate video track
const stream =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ The promise will reject if:
### Basic restriction example

```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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ A {{jsxref("Promise")}} that resolves to a {{domxref("CropTarget")}} object inst
## Examples

```js
// Options for getDisplayMedia()
const displayMediaOptions = {
preferCurrentTab: true,
};

// Create crop target from DOM element
const demoElem = document.querySelector("#demo");
const cropTarget = await CropTarget.fromElement(demoArea);
const cropTarget = await CropTarget.fromElement(demoElem);

// Capture video stream from user's webcam and isolate video track
const stream =
Expand Down
7 changes: 6 additions & 1 deletion files/en-us/web/api/croptarget/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ The **`CropTarget`** interface of the {{domxref("Screen Capture extensions", "Sc
## Examples

```js
// Options for getDisplayMedia()
const displayMediaOptions = {
preferCurrentTab: true,
};

// Create crop target from DOM element
const demoElem = document.querySelector("#demo");
const cropTarget = await CropTarget.fromElement(demoArea);
const cropTarget = await CropTarget.fromElement(demoElem);

// Capture video stream from user's webcam and isolate video track
const stream =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ The promise will reject if the restriction target element is not eligible for re
## 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);
Expand Down
5 changes: 5 additions & 0 deletions files/en-us/web/api/restrictiontarget/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ The **`RestrictionTarget`** interface of the {{domxref("Screen Capture extension
## 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,22 @@ const demoElem = document.querySelector("#demo");
Now let's examine the Region Capture demo's `startCapture()` function:

```js
const displayMediaOptions = {
video: {
displaySurface: "window",
},
audio: false,
preferCurrentTab: true,
};

async function startCapture() {
logElem.textContent = "";

try {
const stream =
await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
const [track] = stream.getVideoTracks();
const cropTarget = await CropTarget.fromElement(demoArea);
const cropTarget = await CropTarget.fromElement(demoElem);
await track.cropTo(cropTarget);

videoElem.srcObject = stream;
Expand Down Expand Up @@ -350,3 +358,4 @@ As a result, it is generally recommended that you use the newer Element Capture

- [Screen Capture extensions](/en-US/docs/Web/API/Screen_Capture_extensions)
- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API)
- [Element Capture Demo](https://element-capture-demo.glitch.me/)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include the region capture demo here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

2 changes: 2 additions & 0 deletions files/en-us/web/api/screen_capture_extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ See [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Scre

For demos, see our [Screen Capture API demos](https://mdn.github.io/dom-examples/screen-capture-api) GitHub directory. See [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_extensions/Element_Region_Capture) for code explanation.

See also [Element Capture Demo](https://element-capture-demo.glitch.me/).

## Specifications

{{Specifications}}
Expand Down