Skip to content

jacksonlai/macaca-electron

 
 

Repository files navigation

macaca-electron

Gitter Chat NPM version build status Test coverage node version

macaca electron driver

Installment

$ npm i macaca-electron -g

Notice

window.alert

Macaca disables window.alert, window.prompt, window.confirm from popping up by default, and you can override by execute.

Standalone usage

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();
});

Packages

No packages published

Languages

  • JavaScript 93.1%
  • HTML 4.4%
  • Makefile 2.5%