Skip to content

docs: improve desktop capture example - #42957

Merged
codebytere merged 1 commit into
mainfrom
display-media-desktop-capturer
Jul 23, 2024
Merged

codebytere merged 1 commit into
mainfrom
display-media-desktop-capturer

Conversation

@codebytere

Copy link
Copy Markdown
Member

Description of Change

Closes #42605.

Updates desktopCapturer example to reflect our current recommendations - this wasn't updated after we added support for navigator.mediaDevices.requestDisplayMedia via #30702

Checklist

Release Notes

Notes: none

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/30-x-y PR should also be added to the "30-x-y" branch. target/31-x-y PR should also be added to the "31-x-y" branch. target/32-x-y PR should also be added to the "32-x-y" branch. labels Jul 18, 2024
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jul 18, 2024
@codebytere
codebytere requested review from erickzhao and removed request for deepak1556 July 18, 2024 08:34
@dsanders11

Copy link
Copy Markdown
Member

cc @electron/docs

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jul 19, 2024
@codebytere
codebytere merged commit 3c9d445 into main Jul 23, 2024
@codebytere
codebytere deleted the display-media-desktop-capturer branch July 23, 2024 09:55
@release-clerk

release-clerk Bot commented Jul 23, 2024

Copy link
Copy Markdown

No Release Notes

@trop

trop Bot commented Jul 23, 2024

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "30-x-y", please check out #43004

@trop trop Bot added in-flight/30-x-y and removed target/30-x-y PR should also be added to the "30-x-y" branch. labels Jul 23, 2024
@trop

trop Bot commented Jul 23, 2024

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "31-x-y", please check out #43005

@trop

trop Bot commented Jul 23, 2024

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "32-x-y", please check out #43006

@trop trop Bot added in-flight/31-x-y in-flight/32-x-y and removed target/31-x-y PR should also be added to the "31-x-y" branch. target/32-x-y PR should also be added to the "32-x-y" branch. labels Jul 23, 2024
@trop trop Bot added merged/32-x-y PR was merged to the "32-x-y" branch. merged/31-x-y PR was merged to the "31-x-y" branch. merged/30-x-y PR was merged to the "30-x-y" branch. and removed in-flight/32-x-y in-flight/31-x-y in-flight/30-x-y labels Jul 23, 2024
Comment on lines -67 to -84
To capture both audio and video from the entire desktop the constraints passed
to [`navigator.mediaDevices.getUserMedia`][] must include `chromeMediaSource: 'desktop'`,
for both `audio` and `video`, but should not include a `chromeMediaSourceId` constraint.
See [`navigator.mediaDevices.getDisplayMedia`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia) for more information.

```js
const constraints = {
audio: {
mandatory: {
chromeMediaSource: 'desktop'
}
},
video: {
mandatory: {
chromeMediaSource: 'desktop'
}
}
}
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This option is still available in Electron, but not mentioned in the docs anymore. As far as I know, this is the only way to capture an entire desktop with multiple screens.

Was it removed intentionally? If it was - what it the recommended way to capture an entire screen? I know, it doesn't work on macOS, but it does on Windows and Linux (except Wayland).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@codebytere I'm here from reading #42605. I'm trying to understand the state of capturing loopback audio in Electron on macOS right now.

Many others are in a similar state of confusion. It's a frequent question on the /r/electron subreddit, on the Electron Discord server, and on StackOverflow, for example. I think the docs leave users lost as to the best practices for handling macOS. Has the situation improved recently? I noticed that there is some ScreenCaptureKit-based code for recording audio loopback in the Chromium macOS source code, so I am wondering what that means for Electron as of today.

Would love any information you can spare! Particularly interested in whether it's possible to record just the desktop audio without capturing video.

@shirakaba shirakaba Apr 23, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Update: I checked for myself and I'm happy to report some success, so my questions are answered.

  • The getUserMedia() example given in this older commit of the docs:
    • works on Windows.
    • throws an error on macOS:

      main_window#/recording:1 The AudioContext encountered an error from the audio device or the WebAudio renderer.

  • The getDisplayMedia() example given in the current PR (committed in this commit):
    • I didn't test on Windows.
    • Does work on macOS! 🥳 I was able to succesfully record both microphone and desktop audio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/30-x-y PR was merged to the "30-x-y" branch. merged/31-x-y PR was merged to the "31-x-y" branch. merged/32-x-y PR was merged to the "32-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Enable Chromium MacLoopbackAudioForScreenShare flag

5 participants