-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
base: main
Are you sure you want to change the base?
Add documentation for Screen Capture extensions, element capture and region capture #36939
Conversation
mdn/mdn#580 could be close with this PR |
Cool, thanks for the heads-up @skyclouds2001. I'll update the description to mention it. |
…ls/content into region-and-element-capture
files/en-us/web/api/browsercapturemediastreamtrack/cropto/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/api/browsercapturemediastreamtrack/clone/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); |
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.
I believe you can remove displayMediaOptions
everywhere as {video: true}
is the default where it works.
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 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,
};
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.
Gotcha. Note that preferCurrentTab
is a hint, and that user can still pick another tab/screen/display.
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.
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.
In Chrome yes, but spec says "SHOULD". See https://wicg.github.io/prefer-current-tab/#ref-for-dom-mediastreamconstraints-prefercurrenttab-1
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.
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.
files/en-us/web/api/screen_capture_extensions/element_region_capture/index.md
Show resolved
Hide resolved
|
||
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. |
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.
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
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.
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.
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.
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.
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.
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?
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.
Let's hold off if that's okay.
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.
OK, that's fine.
video: { | ||
displaySurface: "window", | ||
}, | ||
audio: false, |
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.
audio: false
is the default option
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.
ok, makes sense to remove it in the guide. I have done so.
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
dom-examples
addition: Add DOM examples for Screen Capture API dom-examples#285. The linked demos won't work until this PR is merged.