macaca electron driver
$ npm i macaca-electron -g
Macaca disables window.alert
, window.prompt
, window.confirm
from popping up by default, and you can override by execute
.
const co = require('co');
const fs = require('fs');
const path = require('path');
const Electron = require('macaca-electron');
const electron = new Electron();
co(function *() {
/**
default options
{
show: true,
alwaysOnTop: false,
x: 0,
y: 0,
width: 800,
height: 600,
userAgent: 'userAgent string',
webPreferences: {
nodeIntegration: false
}
}
*/
yield electron.startDevice({
show: false // in silence
});
yield electron.maximize();
yield electron.setWindowSize(null, 500, 500);
yield electron.get('https://www.baidu.com');
const imgData = yield electron.getScreenshot();
const img = new Buffer(imgData, 'base64');
const p = path.join(__dirname, '..', 'screenshot.png')
fs.writeFileSync(p, img.toString('binary'), 'binary');
console.log(`screenshot: ${p}`);
yield electron.stopDevice();
});