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

Conversation

chrisdavidmills
Copy link
Contributor

@chrisdavidmills chrisdavidmills commented Nov 23, 2024

Description

Motivation

Chrome supports extensions to the Screen Capture API that allow developers to limit the region of the capture. Namely, these are:

This PR adds documentation for these APIs.

Additional details

Related issues and pull requests

Fixes mdn/mdn#580

@chrisdavidmills chrisdavidmills requested review from a team as code owners November 23, 2024 16:52
@chrisdavidmills chrisdavidmills requested review from sideshowbarker and bsmth and removed request for a team November 23, 2024 16:52
@chrisdavidmills chrisdavidmills marked this pull request as draft November 23, 2024 16:52
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Nov 23, 2024
Copy link
Contributor

github-actions bot commented Nov 23, 2024

Preview URLs (10 pages)
External URLs (11)

URL: /en-US/docs/Web/API/BrowserCaptureMediaStreamTrack/cropTo
Title: BrowserCaptureMediaStreamTrack: cropTo() method


URL: /en-US/docs/Web/API/BrowserCaptureMediaStreamTrack/restrictTo
Title: BrowserCaptureMediaStreamTrack: restrictTo() method


URL: /en-US/docs/Web/API/BrowserCaptureMediaStreamTrack/clone
Title: BrowserCaptureMediaStreamTrack: clone() method


URL: /en-US/docs/Web/API/Screen_Capture_API/Element_Region_Capture
Title: Using the Element Capture and Region Capture APIs

(comment last updated: 2025-02-07 11:15:03)

@skyclouds2001
Copy link
Contributor

mdn/mdn#580 could be close with this PR

@chrisdavidmills
Copy link
Contributor Author

mdn/mdn#580 could be close with this PR

Cool, thanks for the heads-up @skyclouds2001. I'll update the description to mention it.

@github-actions github-actions bot added size/l [PR only] 501-1000 LoC changed and removed size/m [PR only] 51-500 LoC changed labels Nov 26, 2024
@chrisdavidmills chrisdavidmills marked this pull request as ready for review November 26, 2024 14:58
@chrisdavidmills chrisdavidmills changed the title Add documentation for Screen Capture extensions, element capture and region capture Editorial review: Add documentation for Screen Capture extensions, element capture and region capture Feb 4, 2025
Copy link

@eladalon1983 eladalon1983 left a comment

Choose a reason for hiding this comment

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

LGTM % comment

@wbamberg
Copy link
Collaborator

wbamberg commented Feb 4, 2025

One kind of overall comment on this is that I think it would be better to present this as part of the Screen Capture API, not as an additional separate API. It's a similar case to https://github.com/orgs/mdn/discussions/683 and similar considerations apply.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

These are just comments on the guide, because I started there.

Comment on lines 13 to 21
## Background

The [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API) was created specifically to allow apps to capture the user's screen — or a particular window or tab — and then do something with the resulting stream (such as transmit it to multiple peers via [WebRTC](/en-US/docs/Web/API/WebRTC_API)). The main use case is video conferencing apps, where a user might wish to share a demo running on their local machine with other participants.

The problem with the Screen Capture API is that, by default, it only allows you to broadcast the entire window, screen, or tab selected by the user. Often it would be preferrable to share only a limited region to cut down on unnecessary bandwidth or screen space required to show the capture, or for privacy reasons (you might not want to show other participants your message notifications, or background settings required to run the demo you are sharing). In addition, such apps generally capture your web cam output, meaning that you will likely end up with one of those undesirable "infinite wormhole" or "hall of mirrors" type effects.

To solve such problems, extensions to the Screen Capture API were invented to allow you to restrict the captured stream to a particular subsection of the screen, window, or tab.

In the next section we'll start with a basic Screen Capture API demo to illustrate the issues described above.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This section presents these features in a kind of temporal way:

  • the SC API was invented
  • it has some problems
  • to solve them, some new extensions were added

I think this kind of story works for say a blog post about the new stuff but not so well for reference docs - in 2 years time noone is going to care about the story. It's better just to present the new features as features, and use the present tense, e.g.: "By default, the Screen Capture API captures an entire screen, window, or tab. The element capture and region capture extensions to the API enable you to restrict the captured stream to a specific rendered DOM tree, or to the part of the screen defined by a specific DOM tree's bounding box. This is useful when..."

Copy link
Collaborator

Choose a reason for hiding this comment

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

note also that if we do merge these APIs into the main SC API, I think we should stop capitalizing them, because they're not a title, they're not reified. They're more a part of another API, like we might talk about "how to stream requests", not "how to use the Request Streaming API".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call; I have cut down the background section as advised.

However, I'm not sure I should stop capitalizing "Region Capture API" and "Element Capture API" — they are defined in their own specs; they are standalone things. Those things just so happen to extend another API?


## Screen Capture API demo

This demo uses the Screen Capture API to capture a window, screen, or tab, and broadcast the stream via a {{htmlelement("video")}} element on the same page. It also logs the track settings and constraints to a log container below the main app.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does logging the settings add anything to the tutorial? If not we should omit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think you've probably got a point here. I just blindly copied it over when I made these demos based on the original demo on the Screen Capture API usage guide. It doesn't add anything; it just makes the demos more complicated than necessary.

I've removed the demo code in mdn/dom-examples#294. I'll remove it from these code blocks as well.

page-type: guide
---

{{SeeCompatTable}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not appear in a guide page (there is no compat table to link)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

D'oh! Good point; removed.


{{SeeCompatTable}}

{{DefaultAPISidebar("Screen Capture extensions")}}{{securecontext_header}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

{{securecontext_header}} I think should also be omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

<pre id="log"></pre>
```

### CSS
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to go into the CSS. Apart from the video rule, I don't think it is relevant, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've hidden most of it now, so the section is a lot shorter than it was. I still think it is worth talking about the couple of bits I'm showing here. They are relevant to the usage of the APIs themselves.

Comment on lines 317 to 324
### Stopping the cropping

You can stop the cropping by making a call to `cropTo()` on the same track, passing an argument of `null` to it:

```js
// Stop cropping
await track.cropTo(null);
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again I'd consider excluding this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made into a note, as per previous comment.

await track.cropTo(null);
```

### Issues with the Region Capture API
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again "restrictions" feels better than "issues".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 342 to 345
- The element will not be cropped to if it is off-screen.
- The element will not be cropped to if the track being cropped has clones or is not a track captured from the user's screen.
- The element will not be captured if the `cropTarget` was created in a tab other than the one being captured.
- Because Region Capture 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 stream.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider:

Suggested change
- The element will not be cropped to if it is off-screen.
- The element will not be cropped to if the track being cropped has clones or is not a track captured from the user's screen.
- The element will not be captured if the `cropTarget` was created in a tab other than the one being captured.
- Because Region Capture 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 stream.
The element will not be cropped if any of the following conditions apply:
- It is off-screen.
- The track being cropped has clones or is not a track captured from the user's screen.
- The `cropTarget` was created in a tab other than the one being captured.
Because Region Capture 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 stream.

The fourth is not a condition. Same question about restriction 3 though - how is this possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

There are legitimate use cases for both:

- If you need to keep the capture specific to one DOM tree, and exclude anything outside it, then the Element Capture API is a better choice. For example, you don't want private content such as a set of message notifications or a speaker notes UI showing up in the capture.
- However, if you really do want to capture a region of the browser tab, regardless of what is shown in it, the Region Capture API will serve you well. The [Region Capture Demo](https://region-capture-demo.glitch.me/) shows a useful possibility — zooming in on a particular area of the tab as you show multiple users an interactive walkthrough of some kind.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wish I could see the source code for this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

source code link added


- [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

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

Comments on the rest :).


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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The guide page says:

The element will not be cropped to if the track being cropped has clones or is not a track captured from the user's screen.

Is there anything we should capture in this API page about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note added

- 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 has clones or is not a track captured from the user's screen.
- `CropTarget` is not one of the values specified above.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Contributor Author

@chrisdavidmills chrisdavidmills Feb 5, 2025

Choose a reason for hiding this comment

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

Sorry, that was really vague. I rewrote it to

  • CropTarget is not a {{domxref("CropTarget")}} instance, null, or undefined.

- The crop target element no longer exists.
- The track being cropped has clones or is not a track captured from the user's screen.
- `CropTarget` is not one of the values specified above.
- `CropTarget` was created in a tab other than the one being captured.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question as in the guide page, how is this possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as other page; deleted!

- {{domxref("BrowserCaptureMediaStreamTrack.cropTo", "cropTo()")}} {{Experimental_Inline}}
- : Crops a self-capture stream to the area in which a specified crop target element is rendered.
- {{domxref("BrowserCaptureMediaStreamTrack.restrictTo", "restrictTo()")}} {{Experimental_Inline}}
- : Restricts a self-capture stream to a specific rendered restriction target element.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"a specific rendered restriction target element" is a mouthful. What do we lose if we just say "a specific part of the DOM"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing. Updated!

Comment on lines 30 to 34
- 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 has clones or is not a track captured from the user's screen.
- `RestrictionTarget` is not one of the values specified above.
- `RestrictionTarget` was created in a tab other than the one being captured.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar questions as for cropTo().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same updates made

- Be rendered (for example, not be off-screen or hidden via `display: none`).
- Contain only one box fragment (for example, not be broken across multiple lines).

If it does not meet the above criteria, it is considered to be **not eligible for restriction**.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if the element initially meets the requirements and then doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tested it — when the capture is underway and the element that is being captured suddenly can no longer be captured (e.g. display: none is set), no error is thrown, and the capture just freezes - it continues to show the last captured frame.

I guess this behavior might differ depending on how it became ineligible.

Do you think I need to mention this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No I guess not. Weird though.


{{APIRef("Screen Capture extensions")}}{{SeeCompatTable}}

The **`RestrictionTarget`** interface of the {{domxref("Screen Capture extensions", "Screen Capture extensions", "", "nocode")}} provides a static method, {{domxref("RestrictionTarget.fromElement_static", "fromElement()")}}, which returns a `RestrictionTarget` instance that can be used to restrict a captured video track to a specified DOM element.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
The **`RestrictionTarget`** interface of the {{domxref("Screen Capture extensions", "Screen Capture extensions", "", "nocode")}} provides a static method, {{domxref("RestrictionTarget.fromElement_static", "fromElement()")}}, which returns a `RestrictionTarget` instance that can be used to restrict a captured video track to a specified DOM element.
The **`RestrictionTarget`** interface of the {{domxref("Screen Capture extensions", "Screen Capture extensions", "", "nocode")}} provides a static method, {{domxref("RestrictionTarget.fromElement_static", "fromElement()")}}, which returns a `RestrictionTarget` instance that can be used to restrict a captured video track to a specified DOM element.
Suggested change
The **`RestrictionTarget`** interface of the {{domxref("Screen Capture extensions", "Screen Capture extensions", "", "nocode")}} provides a static method, {{domxref("RestrictionTarget.fromElement_static", "fromElement()")}}, which returns a `RestrictionTarget` instance that can be used to restrict a captured video track to a specified DOM element.
The **`RestrictionTarget`** interface of the {{domxref("Screen Capture extensions", "Screen Capture extensions", "", "nocode")}} API provides a static method, {{domxref("RestrictionTarget.fromElement_static", "fromElement()")}}, which returns a `RestrictionTarget` instance that can be used to restrict a captured video track to a specified DOM element.

(although of course see my other comment about not making this a standalone API...)

Copy link
Contributor Author

@chrisdavidmills chrisdavidmills Feb 5, 2025

Choose a reason for hiding this comment

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

I moved it all over to the Screen Capture, so this is all good now.

## Static methods

- {{domxref("RestrictionTarget.fromElement_static", "fromElement()")}} {{Experimental_Inline}}
- : Returns a `RestrictionTarget` instance that can be used to crop a captured video track to a specified DOM element.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- : Returns a `RestrictionTarget` instance that can be used to crop a captured video track to a specified DOM element.
- : Returns a `RestrictionTarget` instance that can be used to restrict a captured video track to a specified DOM element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 23 to 31
The Screen Capture API was created specifically to allow apps to capture the user's screen — or a particular window or tab — and then do something with the resulting stream (such as transmit it to multiple peers via [WebRTC](/en-US/docs/Web/API/WebRTC_API)). The main use case is video conferencing apps, where a user might wish to share a demo running on their local machine with other participants.

The problem with the Screen Capture API is that, by default, it only allows you to broadcast the entire window, screen or tab selected by the user. Often it would be preferrable to share only a limited region to cut down on unnecessary bandwidth or screen space required to show the capture, or for privacy reasons (you might not want to show other participants your message notifications, or background settings required to run the demo you are sharing).

The following Screen Capture API extensions provide mechanisms to limit the region captured in the stream:

- The **Element Capture API** restricts the captured region to a specified rendered DOM element.
- The **Region Capture API** crops the captured region to the area of the screen in which a specified DOM element is rendered.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar comments to those about the "Background" bit of the guide, as this is similar content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This page no longer exists.

"CropTarget",
"RestrictionTarget"
],
"methods": ["MediaDevices.getDisplayMedia()"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is weird I think (and might cause weird problems) to include an item in two different APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this API entry no longer exists.

@wbamberg
Copy link
Collaborator

wbamberg commented Feb 5, 2025

Thank you for the updates, Chris!

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

Thank you for those updates Chris! I just had a few more little bits.

}
```

1. Here, we start by grabbing the media stream as before, using, `mediaDevices.getDisplayMedia()`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
1. Here, we start by grabbing the media stream as before, using, `mediaDevices.getDisplayMedia()`.
1. Here, we start by grabbing the media stream as before, using `mediaDevices.getDisplayMedia()`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


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 {{domxref("Window.postMessage()")}}, for example.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, sorry about this! But please see also #36939 (comment).


- The element will not be cropped to if the track being cropped has clones or is not a track captured from the user's screen.
- The element will not be captured if the `cropTarget` was created in a tab other than the one being captured.
- Because Region Capture 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 stream.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a restriction, so doesn't belong in the list. It's actually the key fact about the RC API, and I feel it is a little buried here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved these details to the CropTarget: fromElement() static method page, and put it as a standalone point in the page intro.


## When to use each API

As explained above, Element Capture captures the element itself (and its descendants), whereas Region Capture captures the area of the browser tab defined by the bounding box of the target element. Element Capture will always show just the captured element, even if other DOM content overlaps it, whereas Region Capture can result in overlapping content being shown over the top of the content you intended to share.
Copy link
Collaborator

@wbamberg wbamberg Feb 5, 2025

Choose a reason for hiding this comment

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

Suggested change
As explained above, Element Capture captures the element itself (and its descendants), whereas Region Capture captures the area of the browser tab defined by the bounding box of the target element. Element Capture will always show just the captured element, even if other DOM content overlaps it, whereas Region Capture can result in overlapping content being shown over the top of the content you intended to share.
Element Capture captures the element itself (and its descendants), whereas Region Capture captures the area of the browser tab defined by the bounding box of the target element. Element Capture will always show just the captured element, even if other DOM content overlaps it, whereas Region Capture can result in overlapping content being shown over the top of the content you intended to share.

(I don't think that phrase really adds anything, and it's a bit vague - where is it explained? It's fine to repeat key messages and we don't need to apologize for that :))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. This bit got removed anyway, when I moved this section up to the top of the article. It really didn't make sense up there ;-)


## See also

- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API)

(don't need this link any more, we are already here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines 47 to 49

## Screen Capture extension interfaces

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
## Screen Capture extension interfaces

I think it is better just to present these as interfaces. I don't think anyone really cares that they are defined in a separate specification, at least not to the extent that it merits a separate top-level heading here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I've deleted the heading, and put the interfaces in a single list.

@@ -24,11 +31,29 @@ The {{jsxref("Promise")}} returned by `getDisplayMedia()` resolves to a {{domxre

See the article [Using the Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture) for a more in-depth look at how to use the API to capture screen contents as a stream.

## Screen Capture extensions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again I would not have this as a separate section. I think the developers this is just part of the SC API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, updated

Comment on lines 17 to 18
> [!NOTE]
> When attempting to crop a captured stream using {{domxref("BrowserCaptureMediaStreamTrack.cropTo", "cropTo()")}} or restrict it using {{domxref("BrowserCaptureMediaStreamTrack.restrictTo", "restrictTo()")}}, elements will not be cropped or restricted to if the track being captured has clones.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we instead say something like: "If a track has clones, its cropTo() and restrictTo() will reject with an error." I think this is clearer than "elements will not be cropped or restricted to".

Also I couldn't see a source for this in the specification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See https://developer.chrome.com/docs/web-platform/element-capture#restricting and https://developer.chrome.com/docs/web-platform/region-capture#cropping. I don't think it is in the spec, rather it is a current technical limitation they are trying to work around. But I'm not sure if it is helpful to separate this information out as a result.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the info! It's usually our practice to distinguish between restrictions that are intentional per spec and browser bugs, and I think we ought to do that here, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, done!

- Be rendered (for example, not be off-screen or hidden via `display: none`).
- Contain only one box fragment (for example, not be broken across multiple lines).

If it does not meet the above criteria, it is considered to be **not eligible for restriction**.
Copy link
Collaborator

Choose a reason for hiding this comment

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

No I guess not. Weird though.


## The Region Capture API

The Region Capture API has a very similar effect to the Element Capture API, except that rather than restricting the captured region to a specific rendered DOM tree, it crops the stream to the area of the current browser tab defined by the bounding box of the target element. Let's look at a demo and then explore the differences between the two in more detail later on.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The reason I'm suggesting this is that it's easier, cognitively, on the reader. Otherwise I'm thinking: here are 2 similar APIs, that have some unknown difference, and I have to keep that unanswered question in my head while I'm reading all the demo, until the "reveal" at the end. It's like a puzzle, where I have to work out what the difference is, then I get the answer at the end.

If I get the reveal at the start, then I know what the difference is, and the analysis/walkthrough is all just confirmation, I just nod as I read through.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

Thank you Chris for your patience as always! I'm approving this because it's 99% there and I don't want to block on another round of timezones. I do think it is worth separating out the "clones" limitation from those that are per-spec - for instance having a note like "Note than in Chromium, ... " and linking to the bug. But I don't think it's a blocker, and happy for you to merge either way.

@chrisdavidmills
Copy link
Contributor Author

Thank you Chris for your patience as always! I'm approving this because it's 99% there and I don't want to block on another round of timezones. I do think it is worth separating out the "clones" limitation from those that are per-spec - for instance having a note like "Note than in Chromium, ... " and linking to the bug. But I don't think it's a blocker, and happy for you to merge either way.

Thanks so much @wbamberg for the thorough review. You've helped make this much better.

I've moved the clone restriction info into notes in appropriate places as suggested.

Time to merge!

@chrisdavidmills chrisdavidmills merged commit d9879ec into mdn:main Feb 7, 2025
9 checks passed
@chrisdavidmills chrisdavidmills deleted the region-and-element-capture branch February 7, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/l [PR only] 501-1000 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document for Region Capture API
5 participants