mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
788 B
788 B
Screenshots
For capturing screenshots use Page.screenshot()
.
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {
waitUntil: 'networkidle2',
});
await page.screenshot({
path: 'hn.png',
});
await browser.close();
You can also capture a screenshot of a specific element using ElementHandle.screenshot()
:
const fileElement = await page.waitForSelector('div');
await fileElement.screenshot({
path: 'div.png',
});
By default, ElementHandle.screenshot()
tries to scroll the element into view
if it is hidden.