Created
January 6, 2018 09:57
-
-
Save SuperHuangXu/8cce7273b9543bc2b2f864363839908d to your computer and use it in GitHub Desktop.
使用puppeteer截图
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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