-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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
chrisdavidmills
merged 18 commits into
mdn:main
from
chrisdavidmills:region-and-element-capture
Feb 7, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6edd354
Adding landing page for Screen Capture extrensions
chrisdavidmills 3e80b04
Add usage guide
chrisdavidmills bc36f1c
Add reference pages
chrisdavidmills 96bc1f5
Merge branch 'main' into region-and-element-capture
chrisdavidmills 27e5207
Fix a couple of flaws
chrisdavidmills 536f60a
Merge branch 'region-and-element-capture' of github.com:chrisdavidmil…
chrisdavidmills 5c20d74
Fixes for beaufortfrancois review comments
chrisdavidmills 2e95813
remove audio: false,
chrisdavidmills cb3315e
Make it clearer that preferCurrentTab is a hint
chrisdavidmills fc26a2d
Merge branch 'main' into region-and-element-capture
chrisdavidmills 24d1675
Fix respective use cases content
chrisdavidmills 6f3f1f7
Merge branch 'main' into region-and-element-capture
chrisdavidmills b8dac53
Fixes for last few eladalon comments
chrisdavidmills 8ad73f5
Merge branch 'main' into region-and-element-capture
wbamberg a419c6d
Tighten up prose; remove screen versus tab confusion
chrisdavidmills fa7a504
Fixes for wbamberg review comments
chrisdavidmills 57dafb6
Second round of fixes for wbamberg review comments
chrisdavidmills 0ca8d4d
Separate out browser-specific limitations info
chrisdavidmills File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
files/en-us/web/api/browsercapturemediastreamtrack/clone/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: "BrowserCaptureMediaStreamTrack: clone() method" | ||
short-title: clone() | ||
slug: Web/API/BrowserCaptureMediaStreamTrack/clone | ||
page-type: web-api-instance-method | ||
status: | ||
- experimental | ||
browser-compat: api.BrowserCaptureMediaStreamTrack.clone | ||
--- | ||
|
||
{{APIRef("Screen Capture API")}}{{SeeCompatTable}}{{securecontext_header}} | ||
|
||
The **`clone()`** method of the {{domxref("BrowserCaptureMediaStreamTrack")}} interface returns a clone of the original `BrowserCaptureMediaStreamTrack`. | ||
|
||
This method is functionally identical to {{domxref("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 {{domxref("BrowserCaptureMediaStreamTrack.cropTo", "cropTo()")}} and {{domxref("BrowserCaptureMediaStreamTrack.restrictTo", "restrictTo()")}} methods will reject (see [Chrome issue 41482026](https://issues.chromium.org/issues/41482026)). | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
clone() | ||
``` | ||
|
||
### Parameters | ||
|
||
None. | ||
|
||
### Return value | ||
|
||
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(demoElem); | ||
|
||
// Capture video stream from user's webcam and isolate video track | ||
const stream = | ||
await navigator.mediaDevices.getDisplayMedia(displayMediaOptions); | ||
chrisdavidmills marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const [track] = stream.getVideoTracks(); | ||
|
||
// Crop video track | ||
await track.cropTo(cropTarget); | ||
|
||
// Create uncropped clone of the track | ||
const clonedTrack = track.clone(); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API) | ||
- [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) |
89 changes: 89 additions & 0 deletions
89
files/en-us/web/api/browsercapturemediastreamtrack/cropto/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: "BrowserCaptureMediaStreamTrack: cropTo() method" | ||
short-title: cropTo() | ||
slug: Web/API/BrowserCaptureMediaStreamTrack/cropTo | ||
page-type: web-api-instance-method | ||
status: | ||
- experimental | ||
browser-compat: api.BrowserCaptureMediaStreamTrack.cropTo | ||
--- | ||
|
||
{{APIRef("Screen Capture API")}}{{SeeCompatTable}}{{securecontext_header}} | ||
|
||
The **`cropTo()`** method of the {{domxref("BrowserCaptureMediaStreamTrack")}} interface crops a self-capture stream to the area in which a specified DOM element is rendered. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
cropTo(cropTarget) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `cropTarget` | ||
- : A {{domxref("CropTarget")}} instance representing the element rendering area the stream should be cropped to, or `null`/`undefined`, in which case any previously-set cropping is removed from the track. | ||
chrisdavidmills marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Return value | ||
|
||
A {{jsxref("Promise")}} that resolves to {{jsxref("undefined")}}. | ||
|
||
The promise will reject if: | ||
|
||
- The track [`kind`](/en-US/docs/Web/API/MediaStreamTrack/kind) is not `"video"`, or its [`readyState`](/en-US/docs/Web/API/MediaStreamTrack/readyState) is not `"live"`. | ||
- The crop target element no longer exists. | ||
- The track being cropped is not a track captured from the user's screen. | ||
- `cropTarget` is not a {{domxref("CropTarget")}} instance, `null`, or `undefined`. | ||
- `cropTarget` was created in a tab other than the one being captured. | ||
|
||
> [!NOTE] | ||
> In Chromium, if a track has clones, `cropTo()` will reject (see [Chrome issue 41482026](https://issues.chromium.org/issues/41482026)). | ||
|
||
## Examples | ||
|
||
### 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(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); | ||
|
||
// Broadcast cropped stream in <video> element | ||
videoElem.srcObject = stream; | ||
``` | ||
|
||
See [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) for in-context example code. | ||
|
||
### Stopping the cropping | ||
|
||
You can stop the cropping by making a call to `cropTo()` on a previously-cropped track, passing an argument of `null` to it: | ||
|
||
```js | ||
// Stop cropping | ||
await track.cropTo(null); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API) | ||
- [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) |
40 changes: 40 additions & 0 deletions
40
files/en-us/web/api/browsercapturemediastreamtrack/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: BrowserCaptureMediaStreamTrack | ||
slug: Web/API/BrowserCaptureMediaStreamTrack | ||
page-type: web-api-interface | ||
status: | ||
- experimental | ||
browser-compat: api.BrowserCaptureMediaStreamTrack | ||
--- | ||
|
||
{{APIRef("Screen Capture API")}}{{SeeCompatTable}} | ||
|
||
The **`BrowserCaptureMediaStreamTrack`** interface of the {{domxref("Screen Capture API", "Screen Capture API", "", "nocode")}} represents a single video track. It extends the {{domxref("MediaStreamTrack")}} class with methods to limit the part of a self-capture stream (for example, a user's screen or window) that is captured. | ||
|
||
{{InheritanceDiagram}} | ||
|
||
## Instance methods | ||
|
||
- {{domxref("BrowserCaptureMediaStreamTrack.clone", "clone()")}} {{Experimental_Inline}} | ||
- : Returns an uncropped, unrestricted clone of the original `BrowserCaptureMediaStreamTrack`. | ||
- {{domxref("BrowserCaptureMediaStreamTrack.cropTo", "cropTo()")}} {{Experimental_Inline}} | ||
- : Crops a self-capture stream to the area in which a specified DOM element is rendered. | ||
- {{domxref("BrowserCaptureMediaStreamTrack.restrictTo", "restrictTo()")}} {{Experimental_Inline}} | ||
- : Restricts a self-capture stream to a specific DOM element. | ||
|
||
## Examples | ||
|
||
See [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) for in-context example code. | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API) | ||
- [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) |
87 changes: 87 additions & 0 deletions
87
files/en-us/web/api/browsercapturemediastreamtrack/restrictto/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
title: "BrowserCaptureMediaStreamTrack: restrictTo() method" | ||
short-title: restrictTo() | ||
slug: Web/API/BrowserCaptureMediaStreamTrack/restrictTo | ||
page-type: web-api-instance-method | ||
browser-compat: api.BrowserCaptureMediaStreamTrack.restrictTo | ||
--- | ||
|
||
{{APIRef("Screen Capture API")}}{{SeeCompatTable}}{{securecontext_header}} | ||
|
||
The **`restrictTo()`** method of the {{domxref("BrowserCaptureMediaStreamTrack")}} interface restricts a self-capture stream to a specific DOM element (and its descendants). | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
restrictTo(restrictionTarget) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `restrictionTarget` | ||
- : A {{domxref("RestrictionTarget")}} instance representing the element the stream should be restricted to, or `null`/`undefined`, in which case any previously-set restriction is removed from the track. | ||
chrisdavidmills marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Return value | ||
|
||
A {{jsxref("Promise")}} that resolves to {{jsxref("undefined")}}. | ||
|
||
The promise will reject if: | ||
|
||
- The track [`kind`](/en-US/docs/Web/API/MediaStreamTrack/kind) is not `"video"`, or its [`readyState`](/en-US/docs/Web/API/MediaStreamTrack/readyState) is not `"live"`. | ||
- The restriction target element no longer exists. | ||
- The track being restricted is not a track captured from the user's screen. | ||
- `restrictionTarget` is not a {{domxref("RestrictionTarget")}} instance, `null`, or `undefined`. | ||
- `restrictionTarget` was created in a tab other than the one being captured. | ||
|
||
> [!NOTE] | ||
> In Chromium, if a track has clones, `restrictTo()` will reject (see [Chrome issue 41482026](https://issues.chromium.org/issues/41482026)). | ||
|
||
## Examples | ||
|
||
### 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); | ||
|
||
// 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](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) for in-context example code. | ||
|
||
### Stopping the restriction | ||
|
||
You can stop the restriction by making a call to `restrictTo()` on the same track, passing an argument of `null` to it: | ||
|
||
```js | ||
// Stop restricting | ||
await track.restrictTo(null); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API) | ||
- [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) |
75 changes: 75 additions & 0 deletions
75
files/en-us/web/api/croptarget/fromelement_static/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
title: "CropTarget: fromElement() static method" | ||
short-title: fromElement() | ||
slug: Web/API/CropTarget/fromElement_static | ||
page-type: web-api-static-method | ||
browser-compat: api.CropTarget.fromElement_static | ||
--- | ||
|
||
{{APIRef("Screen Capture API")}}{{SeeCompatTable}}{{securecontext_header}} | ||
|
||
The **`fromElement()`** static method of the {{domxref("CropTarget")}} interface returns a `CropTarget` instance that can be used to crop a captured video track to the area in which a specified element is rendered. | ||
|
||
Because the Region Capture API crops to an area of the current browser tab rather than capturing a specific element, any content drawn on top of the cropped area will be shown in the capture. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
CropTarget.fromElement(element) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `element` | ||
|
||
- : A reference to an {{domxref("Element")}} that you want to use as a crop target. For an element to be used as a crop target, it must be: | ||
|
||
- On-screen | ||
- Visible, that is, not hidden via `display: none` for example. | ||
|
||
In addition, the element will not be captured if the track being restricted has clones (that is, created by {{domxref("BrowserCaptureMediaStreamTrack.clone()")}}) or is captured from a different tab to the current user's tab (passed via {{domxref("Window.postMessage()")}}, for example). | ||
|
||
### Return value | ||
|
||
A {{jsxref("Promise")}} that resolves to a {{domxref("CropTarget")}} object instance, which can then be passed to {{domxref("BrowserCaptureMediaStreamTrack.CropTo()")}} to crop the video captured in the track to just the area the specified DOM element is rendered in. | ||
|
||
`CropTarget` objects are serializable. They can be passed to another document using mechanisms such as {{domxref("Window.postMessage()")}}. | ||
|
||
## 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(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); | ||
|
||
// Broadcast cropped stream in <video> element | ||
videoElem.srcObject = stream; | ||
``` | ||
|
||
See [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) for in-context example code. | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API) | ||
- [Using the Element Capture and Region Capture APIs](/en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guide page says:
Is there anything we should capture in this API page about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note added