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

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

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 extensions under a new tree "Screen Capture extensions", which I felt was preferable to adding a separate docs tree for multiple APIs that do very similar things.

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 (11 pages)
Flaws (4)

Note! 7 documents with no flaws that don't need to be listed. 🎉

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

  • bad_bcd_queries:
    • No BCD data for query: api.BrowserCaptureMediaStreamTrack.restrictTo

URL: /en-US/docs/Web/API/RestrictionTarget
Title: RestrictionTarget
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: api.RestrictionTarget

URL: /en-US/docs/Web/API/RestrictionTarget/fromElement_static
Title: RestrictionTarget: fromElement() static method
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: api.RestrictionTarget.fromElement_static

URL: /en-US/docs/Web/API/Screen_Capture_extensions
Title: Screen Capture extensions
Flaw count: 1

  • bad_bcd_queries:
    • No BCD data for query: api.RestrictionTarget
External URLs (8)

URL: /en-US/docs/Web/API/Screen_Capture_extensions
Title: Screen Capture extensions


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

(comment last updated: 2024-11-29 10:06:42)

@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
files/en-us/web/api/croptarget/fromelement_static/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/croptarget/index.md Outdated Show resolved Hide resolved

// Capture video stream from user's webcam and isolate video track
const stream =
await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can remove displayMediaOptions everywhere as {video: true} is the default where it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The getDisplayMedia() call does work with no options, yes. My concern with this is that to get Region or Element capture working, you need to do a same-tab capture, otherwise, it doesn't work, and to achieve this, you need the preferCurrentTab: true option. Therefore, to be on the safe side, I've decided to include the following minimal options object at the start of each one of these code snippets:

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Note that preferCurrentTab is a hint, and that user can still pick another tab/screen/display.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I run my demo on Chrome, it only gives me the option of selecting the current tab when I start the capture. This is what I get:

Screenshot 2024-11-29 at 10 07 04

Copy link
Contributor

Choose a reason for hiding this comment

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

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, fair enough. I have updated the text in the guide to make it clearer that this is a hint:

This hint suggests that the browser should offer the user's current tab as the most prominent capture source in the dialog that asks them what to share. Chrome, for example, only gives them this option when preferCurrentTab: true is set.


This could be a major problem if that content is private, for example message notifications or speaker notes. If you can't guarantee that your app can keep private content from being shared, then you may lose trust in your users.

As a result, it is generally recommended that you use the newer Element Capture API over the older Region Capture API, unless you need to support older browser versions that do not support Element Capture.
Copy link
Contributor

@beaufortfrancois beaufortfrancois Nov 27, 2024

Choose a reason for hiding this comment

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

I'm not sure that's the right conclusion we aimed regarding these two APIs.
My understanding is that both APIs have legitimate use cases, and that Element Capture does not supersede Region Capture.

FYI @eladalon1983

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'd appreciate some guidance here on what to say here @beaufortfrancois @eladalon1983 — I am not clear on what the distinct use cases are for each.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's okay with you, let's wait until mid-January when @eladalon1983 returns, as there's nothing urgent that needs to be addressed immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that's fine by me. Do you want to get this published before that, and then update with better information once @eladalon1983 returns, or hold off on publication?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's hold off if that's okay.

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, that's fine.

video: {
displaySurface: "window",
},
audio: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

audio: false is the default option

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, makes sense to remove it in the guide. I have done so.

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
3 participants