desktopCapturer

    Process: Main,

    The following example shows how to capture video from a desktop window whose title is Electron:

    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.

    1. const constraints = {
    2. audio: {
    3. chromeMediaSource: 'desktop'
    4. }
    5. },
    6. video: {
    7. mandatory: {
    8. }
    9. }
    10. }

    The desktopCapturer module has the following methods:

    • options Object
      • types String[] - An array of Strings that lists the types of desktop sources to be captured, available types are screen and window.
      • fetchWindowIcons Boolean (optional) - Set to true to enable fetching window icons. The default value is false. When false the appIcon property of the sources return null. Same if a source has the type screen.

    Note Capturing the screen contents requires user consent on macOS 10.15 Catalina or higher, which can detected by .

    Caveats

    does not work on macOS for audio capture due to a fundamental limitation whereby apps that want to access the system’s audio require a . Chromium, and by extension Electron, does not provide this.