Miscellaneous
If you wish to support apps built using versions of ToDesktop Builder before v0.22.3, then you will need to use our older docs on capturing screen contents. See here for the older docs.
Capture Screen Contents
Get the user's media access status
This will return a Promise which will resolve to not-determined, granted, denied, restricted or unknown
On Windows and macOS 10.14 Mojave or lower the response will always begranted . macOS 10.15 Catalina or higher requires consent for screen access.
To get that consent just run the code below, it will automatically ask for permission
Get the user's screen sources
Say we wanted to get a user's screens and windows
This will return an array of sources
Getting a source id
You'll need a way of choosing which screen/window to capture. Unlike in a browser, your Desktop app will need to implement its own UI for this.
For example if you wanted to reproduce a browsers selection feature you could loop through the sources and listen to click events on each.
This will give you something like:

Get the stream to a source
After choosing a source we'll use its id and navigator.mediaDevices.getUserMedia to get the stream.
Play the stream
If you have a <video> in your HTML you can then use
API Reference
getCaptureSources
Exposes the destopCapturer.getSources electron API: https://www.electronjs.org/docs/api/desktop-capturer
Accepts an options object:
typesString - The types of desktop sources to be captured, eitherscreenorwindow.thumbnailSize-{ width: number, height: number }(optional) - Default is150x150.fetchWindowIconsBoolean (optional) - Default value isfalse
Returns a Promise which resolves into an array of DesktopCapturerSource objects each having:
idString - The id of a window or screen that can be used as achromeMediaSourceIdlaternameString - The name of the screen (Entire ScreenorScreen <index>) or the window's titlethumbnailString - A data Url of the imagedisplay_idString - A unique identifier that will correspond to theidpropertyappIconString - A data Url of the app Icon ornullif type is screen
setDisplayMediaRequestHandler
Exposes the session.setDisplayMediaRequestHandler electron API: https://www.electronjs.org/docs/api/session
Accepts a handler function which will be called with the request object and a callback function.
requestObject - The request object (containsframe,securityOrigin,videoRequested,audioRequestedanduserGestureproperties)callbackFunction - The callback function