๋ฐ์ํ
Puppeteer sets an initial page size to 800×600px, which defines the screenshot size.
The page size can be customized with Page.setViewport().
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {
waitUntil: 'networkidle2',
});
await page.pdf({path: 'hn.pdf', format: 'a4'});
await browser.close();
})();
Example - evaluate script in the context of the page
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio,
};
});
console.log('Dimensions:', dimensions);
await browser.close();
})();
const browser = await puppeteer.launch({
headless: true,
args: [`--window-size=1920,1080`],
defaultViewport: { width:1920, height:1080}
});
https://shanepark.tistory.com/291
https://github.com/puppeteer/puppeteer
๋ฐ์ํ
'Web > Node.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Node.js] Bookmarks (0) | 2022.08.01 |
---|---|
npm ์ค์น ์ค๋ฅ SELF_SIGNED_CERT_IN_CHAIN (0) | 2022.08.01 |