Skip to content

Instantly share code, notes, and snippets.

@cr0wg4n
Last active June 22, 2021 03:10
Show Gist options
  • Save cr0wg4n/ac47becc4882e7c06325f83d5a95c11a to your computer and use it in GitHub Desktop.
Save cr0wg4n/ac47becc4882e7c06325f83d5a95c11a to your computer and use it in GitHub Desktop.
realizar captura con electron.js
const electron = require('electron')
function takeScreenshot () {
electron.remote.getCurrentWindow().capturePage({
x: 0,
y: 0,
width: 2000,
height: 4000,
}).then((img) => {
dialog.showSaveDialog({
title: 'save screenshot',
defaultPath: require('os').homedir(),
buttonLabel: 'Guardar',
filters: [
{
name: 'Image Files',
extensions: ["png", "jpeg", "jpg"]
}
],
properties: []
}).then(file => {
if (!file.canceled) {
try {
fs.writeFileSync(file.filePath.toString(), img.toPNG(), 'base64')
} catch (error) {
console.log(error)
}
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment