33 lines
930 B
JavaScript
33 lines
930 B
JavaScript
const puppeteer = require('puppeteer');
|
|
const path = require('path');
|
|
|
|
(async () => {
|
|
const browser = await puppeteer.launch({
|
|
headless: true,
|
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
});
|
|
const page = await browser.newPage();
|
|
|
|
// 设置视口大小
|
|
await page.setViewport({ width: 1400, height: 1200 });
|
|
|
|
const filePath = 'file://' + path.resolve(__dirname, 'screenshots.html');
|
|
console.log('Loading:', filePath);
|
|
|
|
await page.goto(filePath, { waitUntil: 'networkidle0' });
|
|
|
|
// 等待内容加载
|
|
await page.waitForSelector('.phone-frame', { timeout: 10000 });
|
|
|
|
// 截图整个页面
|
|
const outputPath = path.resolve(__dirname, 'screenshots-full.png');
|
|
await page.screenshot({
|
|
path: outputPath,
|
|
fullPage: true
|
|
});
|
|
|
|
console.log('Full page screenshot saved:', outputPath);
|
|
|
|
await browser.close();
|
|
console.log('Done!');
|
|
})(); |