Repository navigation
docs: improve desktop-capturer loopback docs - #47493
alectrocute wants to merge 5 commits into
Conversation
|
💖 Thanks for opening this pull request! 💖 Semantic PR titlesWe use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix. Examples of commit messages with semantic prefixes:
Commit signingThis repo enforces commit signatures for all incoming PRs. PR tipsThings that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
nikwen
left a comment
There was a problem hiding this comment.
Thank you so much for the docs change! Appreciate that a lot!
I'll take a closer look when I'm at a computer.
Could you please wrap lines between 80 and 100 characters as per our docs style guide?
| <button id="startButton" class="button">Start</button> | ||
| <button id="stopButton" class="button">Stop</button> | ||
| <video width="320" height="240" autoplay></video> | ||
| <video width="320" height="240" autoplay controls></video> |
There was a problem hiding this comment.
DX improvement: controls being visible is important for the dev to be able to easily determine if there's an audio track available or not.
|
Thanks so much @nikwen! I took your feedback and ran with it, rewrote a bunch of stuff and added even more clarity. Let me know what you think! |
nikwen
left a comment
There was a problem hiding this comment.
Thanks! This is great.
Also requesting a review from @codebytere as she probably has the best understanding of that code.
|
Thanks so much, @nikwen. I've applied your feedback. Last thing I'm debating is adding a "macOS Caveats" header to lead the "System Audio Capture" sections at the bottom. I kinda feel like the macOS notes at the bottom come out of nowhere. Thoughts? |
I think that's a great idea. Thanks! |
Done—Looks much better now. |
There was a problem hiding this comment.
Thank you so much!
I found some more comments on other ways to make loopback audio capture work on macOS 14.2+:
I wonder if that would work around the macOS 15 bugs. (Or does it introduce new ones?)
Also added some minor things inline. This PR is in pretty good shape now in my opinion.
|
|
||
| ### System Audio Capture (before macOS 12.3) | ||
|
|
||
| On macOS 12.3 or lower, system audio capture is not supported due to a fundamental limitation whereby |
There was a problem hiding this comment.
| On macOS 12.3 or lower, system audio capture is not supported due to a fundamental limitation whereby | |
| Before macOS 12.3, system audio capture is not supported due to a fundamental limitation whereby |
Sounds like it works on 12.3.
There was a problem hiding this comment.
You can indeed try opting in to it by enabling the MacSckSystemAudioLoopbackOverride flag, but one downstream codepath regards ScreenCaptureKit as too buggy to use until 13.2, so I'm not sure it'll work in practice.
There was a problem hiding this comment.
Yeah, I was playing it safe here. We can and probably should get more specific.
| ### System Audio Capture (before macOS 12.3) | ||
|
|
||
| On macOS 12.3 or lower, system audio capture is not supported due to a fundamental limitation whereby | ||
| apps that want to access the system's audio require a [signed kernel extension](https://developer.apple.com/library/archive/documentation/Security/ConceptualSystem_Integrity_Protection_Guide/KernelExtensions/KernelExtensions.html). |
There was a problem hiding this comment.
| apps that want to access the system's audio require a [signed kernel extension](https://developer.apple.com/library/archive/documentation/Security/ConceptualSystem_Integrity_Protection_Guide/KernelExtensions/KernelExtensions.html). | |
| apps that want to access the system's audio require a | |
| [signed kernel extension](https://developer.apple.com/library/archive/documentation/Security/ConceptualSystem_Integrity_Protection_Guide/KernelExtensions/KernelExtensions.html). |
Wrapping between 80 and 100 chars.
There was a problem hiding this comment.
I guess I'm a total markdown noob but how do I wrap a long URL link without breaking it? Whenever I try to split that big string, it breaks the link in my Markdown Preview.
There was a problem hiding this comment.
Yes, links can't be wrapped. It's okay if links are longer if they are the only thing in a line.
| > ```js | ||
| > // main.js | ||
| > app.commandLine.appendSwitch('enable-features', 'MacSckSystemAudioLoopbackOverride'); | ||
| > ``` |
There was a problem hiding this comment.
This comment sounds like it is also needed on macOS 12: https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/flag_descriptions.cc;l=6247-6253;drc=19d14ae4a957ef0f158e3b37cc7f3c76e839ce5d
There was a problem hiding this comment.
You can indeed try opting in to it by enabling the MacSckSystemAudioLoopbackOverride flag, but one downstream codepath regards ScreenCaptureKit as too buggy to use until 13.2, so I'm not sure it'll work in practice.
There was a problem hiding this comment.
I honestly just need to test this on macOS 12.x to get to the bottom of it. I was erring on the side of caution here.
shirakaba
left a comment
There was a problem hiding this comment.
I do think the desktopCapturer docs need some clarifying for macOS. They have led me (and, judging by weekly threads on Reddit, many others) astray. These changes help a lot, thanks!
| ### System Audio Capture (macOS 12.3+) | ||
|
|
||
| It is possible to circumvent this limitation by capturing system audio with another macOS app like Soundflower and passing it through a virtual audio input device. This virtual device can then be queried with `navigator.mediaDevices.getUserMedia`. | ||
| On macOS 12.3+, `navigator.mediaDevices.getDisplayMedia` can be used to capture system audio |
There was a problem hiding this comment.
Would be good to be explicit about which macOS versions, if any, navigator.mediaDevices.getUserMedia() can be used on.
I seem to recall from recent testing on macOS 14.6.1 that it can't be used at all, but worth double-checking before reporting it in the docs.
| > [!NOTE] | ||
| > Due to ongoing changes in Chromium, capturing system audio is experimental on macOS 15+ and requires the | ||
| > following [command line switch](./command-line-switches.md) to be appended. Please note that you may experience bugs. | ||
| > | ||
| > ```js | ||
| > // main.js | ||
| > app.commandLine.appendSwitch('enable-features', 'MacSckSystemAudioLoopbackOverride'); | ||
| > ``` |
There was a problem hiding this comment.
I think this is inaccurate.
Looking at how IsSystemLoopbackCaptureSupported() is implemented in Chromium, loopback capture depends on both the macOS version and the state of the MacSckSystemAudioLoopbackOverride and MacCatapSystemAudioLoopbackCapture flags (which are both disabled by default). The audio system used may be based on ScreenCaptureKit or Core Audio taps.
- 🔴
version < 12.3:- Loopback capture is not possible.
- 🔴
12.3 ≤ version < 13.0:- Loopback capture is probably not possible. Although ScreenCaptureKit is technically available from macOS 12.3, the Chromium codebase notes that it is too buggy to activate until 13.2. You can try enabling the
MacSckSystemAudioLoopbackOverrideflag to opt in to it, but I think it won't work in practice.
- Loopback capture is probably not possible. Although ScreenCaptureKit is technically available from macOS 12.3, the Chromium codebase notes that it is too buggy to activate until 13.2. You can try enabling the
- 🔴
13.0 ≤ version < 13.2:- Loopback capture is probably not possible. Although the top-level IsMacSckSystemAudioLoopbackCaptureEnabled() check defaults to
truefor this version range (meaning that the ScreenCaptureKit implementation is enabled even without enabling theMacSckSystemAudioLoopbackOverrideflag), in practice, certain downstream codepaths treat it as too buggy to activate.
- Loopback capture is probably not possible. Although the top-level IsMacSckSystemAudioLoopbackCaptureEnabled() check defaults to
- 🟢
13.2 ≤ version < 14.2:- Loopback capture is possible, via ScreenCaptureKit only, and is enabled by default; no flag needed.
- 🟢
14.2 ≤ version < 15.0:- Loopback capture is possible, via either ScreenCaptureKit or Core Audio taps. By default, it is enabled, and done via ScreenCaptureKit. However, you can opt-in to Core Audio taps instead by enabling the
MacCatapSystemAudioLoopbackCaptureflag (which takes precedence).
- Loopback capture is possible, via either ScreenCaptureKit or Core Audio taps. By default, it is enabled, and done via ScreenCaptureKit. However, you can opt-in to Core Audio taps instead by enabling the
- 🟡
15.0 ≤ version:- Loopback capture is possible, via either ScreenCaptureKit or Core Audio taps. By default, it is disabled altogether.
- To enable it via Core Audio taps (the preferred approach from macOS 15.0 and above), enable the
MacCatapSystemAudioLoopbackCaptureflag. As this flag takes precedence, it doesn't matter whetherMacSckSystemAudioLoopbackOverrideis enabled or disabled. - To enable it via ScreenCaptureKit (not recommended, due to permissions prompt issues from macOS 15.0), you must enable the
MacSckSystemAudioLoopbackOverrideflag and disable/omit theMacCatapSystemAudioLoopbackCaptureflag.
- To enable it via Core Audio taps (the preferred approach from macOS 15.0 and above), enable the
- Loopback capture is possible, via either ScreenCaptureKit or Core Audio taps. By default, it is disabled altogether.
So, in summary, to support the maximum version range of 13.2 ≤ version, you should enable the MacCatapSystemAudioLoopbackCapture flag to extend support for version ≥ 15.0.
If both the MacSckSystemAudioLoopbackOverride and MacCatapSystemAudioLoopbackCapture flags are enabled, the latter will take precedence.
I should clarify that this is just based on my analysis of the latest commit on the main branch of Chromium. It might be that things were different in previous versions of Chromium, and it might be that Electron builds Chromium with different flags (however, I find no search results for either).
Does this match your experience?
There was a problem hiding this comment.
This is a great write-up, thank you. I see that there's definitely some inaccuracies that'll need to be fixed here.
Per my experience, talking strictly system audio capture (there very well could be horrible bugs related to screen capture but I haven't really tested that) — For macOS versions 13.2 through 15.5, I'm able to verify that system audio capture works great via ScreenCaptureKit, only flags that are needed are MacSckSystemAudioLoopbackOverride. System permission prompts work fine.
For testing, I've created this little NPM package to make things easy in Electron Fiddle or an example project of your choice: https://github.com/alectrocute/electron-audio-loopback/tree/main
The implementation in my package is all I've tested, so we'll want to definitely reinforce in the docs that a lot of this is still experimental.
There was a problem hiding this comment.
In order to provide complete guidance, the biggest questions in my mind are:
- For
12.3 ≤ version < 13.0:- if you enable
MacSckSystemAudioLoopbackOverride, does loopback capture work?
- if you enable
- For
13.0 ≤ version < 13.2:- without passing any flags, does loopback capture work at all?
- For
15.0 ≤ version:- without passing any flags, does loopback capture work at all?
- if you enable
MacCatapSystemAudioLoopbackCapture, does loopback capture work?
There was a problem hiding this comment.
- For
12.3 ≤ version < 13.0:
I will report back.
- For
13.0 ≤ version < 13.2:
I will report back.
For
15.0 ≤ version:
- without passing any flags, does loopback capture work at all?
I can verify that without passing any flags, loopback capture does not work. No errors thrown, the getDisplayMedia audio media track just arrives in an ended state.
- if you pass
MacCatapSystemAudioLoopbackCapture, does loopback capture work?
I will report back.
There was a problem hiding this comment.
Another question:
With MacCatapSystemAudioLoopbackCapture enabled, does it mean that it only requires System Audio Recording Only, versus Screen & System Audio Recording?
Since many apps just need the audio, I'm wondering if chromium supports this mode.
Ofc MDN says getDisplayMedia({ audio: true, video: false }) is not supported but using Core Audio Tap for audio is not a huge benefit if Screen Recording is necessary anyway.
There was a problem hiding this comment.
With
MacCatapSystemAudioLoopbackCaptureenabled, does it mean that it only requiresSystem Audio Recording Only, versusScreen & System Audio Recording?
To explain for others, this is referring to two different lists in System Settings > Privacy & Security > Screen & System Audio Recording: Screen & System Audio Recording and System Audio Recording Only.
I've not tried setting MacCatapSystemAudioLoopbackCapture myself, so I can only guess.
- The Electron app I am developing, which doesn't pass any Chromium flags at all, appears in the
Screen & System Audio Recordinglist in macOS Sonoma 14.6.1. - Apple's ScreenCaptureKit demo requests a permission that places it in the
Screen & System Audio Recordinglist. - insidegui's Core Audio tap demo requests a permission that places it in the
System Audio Recording Onlylist.
Based on that, there's a good possibility that enabling MacCatapSystemAudioLoopbackCapture would cause your app to request a permission that places it in the System Audio Recording Only list instead.
Ofc MDN says
getDisplayMedia({ audio: true, video: false })is not supported but using Core Audio Tap for audio is not a huge benefit if Screen Recording is necessary anyway.
Yes, that's is a good counterpoint, Chromium may still have to record the screen, so it may be a moot point anyway. I think we can only be sure by giving it a try.
@nikwen I looked into these when doing my analysis in this comment. I think the flag descriptions are unhelpful, as they don't reflect the full behaviour as to how they're treated in the source (e.g. how |
|
Thanks, @shirakaba and @alectrocute, for diving further into this. Can you ping me (@nikwen) when you've figured out how it all works and have updated the PR? I'll be honest: I've never worked with system audio capture in Electron. |
|
I feel we have most of the picture based on my comment showing the version compatibility ranges. However, as this was purely a code-level analysis, I was waiting for confirmation of some of my conclusions so that we could confidently update the docs without misleading anyone. We could probably still update the docs with some of the research from my analysis as-is, just using the term "may" tactically:
|
|
Sorry, I swear I've been meaning to get back to this, I'm just swamped at my full-time. Will return to this in the next 7 days @shirakaba! |
|
@alectrocute do you still plan to pursue this? |
Hey @codebytere! I do indeed—I've been chipping away at my OSS backlog and I'm almost ready to return to this. |
|
I've tested Core Audio Tap in macOS 15 and macOS 26 using electron 37.3.0 with session.defaultSession.setDisplayMediaRequestHandler((event, callback) => {
callback({ audio: "loopback" });
});And attempting to get media stream using macOS 15.5
macOS 26.0
Apple have created a guide for using Core Audio Taps targetting macOS 26+, I guess this api wasn't public before? Capturing system audio with Core Audio taps PS: MacSckSystemAudioLoopbackOverride works in both versions, although we cannot get only loopback audio without video track. |
@shirakaba in my testing so far (macOS 15.7.1), setting
@aidenlx that's very interesting, and is as close as anyone has got so far to the holy grail of the correct permission being triggered. No menu bar indicator is correct, or rather you should see a tiny dot instead of the big screen icon:
(Note in this case the dot is orange because I'm using mic and sys audio, but it would be purple otherwise)
This is a total rug pull by Apple. Core Audio Taps has been available and stable since 14.2, but once 26.0 was announced they changed that page to indicate that it was 26.0+ only. The page refuses to render via Wayback Machine so I can't prove it other than to say I've been using it with no issues whatsoever on my 14.x laptop and 15.x desktop all year. |
|
@aidenlx @makeusabrew thank you both for the data points! I was hoping it'd all neatly line up with my expectations from the Chromium source code, but so far we've not seen it add up somehow.
This whole time, I've been running under the assumption that Electron (and frameworks like Electron Forge / Electron Builder) don't pass any flags to Chromium, and that the defaults are what I've dug up in the Chromium codebase. But if it turns out that I'm wrong about Chromium's default flags, or have overlooked some flags that Electron (or Electron Forge / Electron Builder) pass to Chromium, it might explain some of the cases mentioned above where recording is possible on macOS ≥ 15.0. Wish we could be sure. Is it possible to print out the flags Chromium was configured with?
You're not dreaming. I wrote Core Audio code using that Capturing system audio with Core Audio taps guide last year. At the time, I wrote these notes about the version support range for the key Core Audio taps features I was using for system audio capture:
And this of course lines up with some of the version ranges mentioned in my reverse-engineering above. |
|
To get the "System Audio Recording Only" permission prompt, I had to add I tested it on macOS 15 and 26 with Electron 39 |
|
@claudiomaxx That should now be included by default thanks to @Bug-Reaper and #49717. |

Description of Change
desktopCaptureraudio loopback on macOSdesktopCapturer: UseScreenCaptureKitAPI to enable capturing loopback audio on macOS #47490.Checklist
npm testpassesRelease Notes
Notes: none