Header menu logo fable-electron-docs-api

desktopCapturer Type

⚠ Process Availability: Main ✔ | Renderer ❌ | Utility ❌ | Exported ✔

Access information about media sources that can be used to capture audio and video from the desktop using the navigator.mediaDevices.getUserMedia API.Process: MainThe following example shows how to capture video from a desktop window whose title is Electron:// main.jsconst { app, BrowserWindow, desktopCapturer, session } = require('electron')app.whenReady().then(() => { const mainWindow = new BrowserWindow() session.defaultSession.setDisplayMediaRequestHandler((request, callback) => { desktopCapturer.getSources({ types: ['screen'] }).then((sources) => { // Grant access to the first screen found. callback({ video: sources[0], audio: 'loopback' }) }) // If true, use the system picker if available. // Note: this is currently experimental. If the system picker // is available, it will be used and the media request handler // will not be invoked. }, { useSystemPicker: true }) mainWindow.loadFile('index.html')})// renderer.jsconst startButton = document.getElementById('startButton')const stopButton = document.getElementById('stopButton')const video = document.querySelector('video')startButton.addEventListener('click', () => { navigator.mediaDevices.getDisplayMedia({ audio: true, video: { width: 320, height: 240, frameRate: 30 } }).then(stream => { video.srcObject = stream video.onloadedmetadata = (e) => video.play() }).catch(e => console.log(e))})stopButton.addEventListener('click', () => { video.pause()}) See navigator.mediaDevices.getDisplayMedia for more information.> [!NOTE] navigator.mediaDevices.getDisplayMedia does not permit the use of deviceId for selection of a source - see specification.

Static members

Static member Description

desktopCapturer.getSources (types, ?thumbnailSize, ?fetchWindowIcons)

Full Usage: desktopCapturer.getSources (types, ?thumbnailSize, ?fetchWindowIcons)

Parameters:
    types : Types[]
    ?thumbnailSize : Size
    ?fetchWindowIcons : bool

Returns: Promise<DesktopCapturerSource[]>
Modifiers: inline

Resolves with an array of DesktopCapturerSource objects, each DesktopCapturerSource represents a screen or an individual window that can be captured.> [!NOTE] Capturing the screen contents requires user consent on macOS 10.15 Catalina or higher, which can detected by systemPreferences.getMediaAccessStatus.

types : Types[]
?thumbnailSize : Size
?fetchWindowIcons : bool
Returns: Promise<DesktopCapturerSource[]>

Type something to start searching.