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.
$ npm i macaca-puppeteer -g
const fs = require('fs');
const path = require('path');
const Puppeteer = require('macaca-puppeteer');
const puppeteer = new Puppeteer();
async function() {
/**
default options
{
headless: false,
x: 0,
y: 0,
width: 800,
height: 600,
userAgent: 'userAgent string'
}
*/
await puppeteer.startDevice({
headless: true // 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();
};
xudafeng |
zivyangll |
snapre |
---|
This project follows the git-contributor spec, auto updated at Tue Apr 19 2022 23:22:01 GMT+0800
.