官方仓库/文档

安装依赖 npm i puppeteer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
width: 750,
height: 5000,
deviceScaleFactor: 1,
});
await page.goto('http://kaige.org');
await page.screenshot({path: 'example.png'});

await browser.close();
})();

打算将小程序海报生成由puppeteer截图来做