Skip to content

Instantly share code, notes, and snippets.

@SuperHuangXu
Created January 6, 2018 09:57
Show Gist options
  • Save SuperHuangXu/8cce7273b9543bc2b2f864363839908d to your computer and use it in GitHub Desktop.
Save SuperHuangXu/8cce7273b9543bc2b2f864363839908d to your computer and use it in GitHub Desktop.
使用puppeteer截图
'use strict';
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
// 设置Chromium位置
executablePath: 'D:\\Program Files (x86)\\Yarn\\chrome\\chrome.exe',
env: {
CHROME_PATH: puppeteer.executablePath(),
},
// 是否显示浏览器
headless: false,
// slow down by 250ms
// slowMo: 250
});
const page = await browser.newPage();
page.setViewport({
width: 1920,
height: 1042,
});
await page.goto('https://blog.superhx.cn', {
// 等待网络状态为空闲的时候才继续执行
waitUntil: 'networkidle2',
});
await page.screenshot({
path: 'example.png',
});
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment