Skip to content

Electron desktopCapturer.getSources().then is not resolved #25595

@pravintamil

Description

@pravintamil

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 10.1.2
  • Operating System:
    • Ubuntu 18.04.5 LTS

Expected Behavior

desktopCapturer.getSources().then should be resolved

Actual Behavior

desktopCapturer.getSources().then is not resolved after 1 minute

To Reproduce

const { app, desktopCapturer, screen } = require('electron');

const fs = require('fs')
const path = require('path')


function takeScreenshot() {
	console.log('Gathering screens...')
	const thumbSize = determineScreenShotSize()
	const options = { types: ['screen'], thumbnailSize: thumbSize }

	desktopCapturer.getSources(options).then((sources) => {
		console.log('Sources received:'+sources.length);
		sources.forEach(function (source) {
			const sourceName = source.name.toLowerCase();
			console.log(sourceName);
			if ( ['entire screen', 'screen 1'].includes(sourceName)) {
				const screenshotPath = path.join(app.getPath('pictures'), 'screenshot-' + new Date().toJSON() + '.png')
				fs.writeFile(screenshotPath, source.thumbnail.toPNG(), function (error) {
					if (error) return console.log(error)
					console.log('Saved screenshot to: ' + screenshotPath);
				})
			}
		})
	}).catch(console.error);
}

function determineScreenShotSize() {
	var screenSize = screen.getPrimaryDisplay().workAreaSize
	return {
		width: screenSize.width,
		height: screenSize.height
	}
}
setInterval(takeScreenshot, 15000);
git clone git@bitbucket.org:praveen-knackforge/electron-boilerplate.git -b screenshot
npm install
npm start || electron .

Screenshots

image

Additional Information

I used desktopCapturer API from the main process

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions