Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

macacajs/macaca-electron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

60e13b1 · Jun 15, 2022
May 7, 2022
Apr 29, 2022
May 9, 2021
Dec 4, 2021
Jan 16, 2020
Apr 22, 2022
Mar 9, 2019
May 6, 2016
Aug 17, 2017
May 7, 2022
Aug 12, 2017
Jun 15, 2022

Repository files navigation

macaca-electron

NPM version Package quality build status Test coverage node version

Macaca Electron driver

Contributors


xudafeng


paradite


meowtec


ziczhu


xianxiaow


cyjake


coffeedeveloper


jacksonlai


sriting


snapre


yihuineng

This project follows the git-contributor spec, auto updated at Sat May 07 2022 23:36:31 GMT+0800.

Installment

$ npm i macaca-electron -g

Release Plan

Simply put, Chromium doesn't stop shipping so Electron is not going to slow down either, so Macaca is not stop...

Starting with Electron version 7, Macaca will always upgrade with the Electron's main version.

Environment Variable

set MACACA_ELECTRON_DEVTOOLS=1 to open the devtools.

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 fs = require('fs');
const path = require('path');
const Electron = require('macaca-electron');

const electron = new Electron();

/**
  default options
  {
    show: true,
    alwaysOnTop: false,
    x: 0,
    y: 0,
    width: 800,
    height: 600,
    userAgent: 'userAgent string',
    webPreferences: {
      nodeIntegration: false
    }
  }
*/
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
  await electron.startDevice({
    show: false // in silence
  });
  await electron.maximize();
  await electron.setWindowSize(null, 500, 500);
  await electron.get('https://www.baidu.com');
  await sleep(3000);
  const imgData = await electron.getScreenshot();
  const img = Buffer.from(imgData, 'base64');
  const p = path.join('screenshot.png');
  fs.writeFileSync(p, img.toString('binary'), 'binary');
  console.log(`screenshot: ${p}`);

  await electron.stopDevice();
})();

License

The MIT License (MIT)