Skip to content

Latest commit

 

History

History
79 lines (61 loc) · 2.61 KB

README.md

File metadata and controls

79 lines (61 loc) · 2.61 KB

macaca-puppeteer

Gitter Chat NPM version build status Test coverage node version

Puppeteer is a Node library which provides a high-level API to control headless Chrome over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome. Macaca Puppeteer is a long-term maintained browser driver as a candidate for Macaca Electron driver.

Installment

$ npm i macaca-puppeteer -g

Usage as module

const fs = require('fs');
const path = require('path');
const Puppeteer = require('macaca-puppeteer');

const puppeteer = new Puppeteer();

async function() {
  /**
    default options
    {
      show: true,
      x: 0,
      y: 0,
      width: 800,
      height: 600,
      userAgent: 'userAgent string'
    }
  */
  await puppeteer.startDevice({
    show: false // in silence
  });

  await puppeteer.maximize();
  await puppeteer.setWindowSize(null, 500, 500);
  await puppeteer.get('https://www.baidu.com');
  const imgData = await puppeteer.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}`);

  await puppeteer.stopDevice();
};

Contributors


xudafeng

This project follows the git-contributor spec, auto upated at Sun Mar 25 2018 16:05:18 GMT+0800.