'use strict'; const path = require('path'); const fs = require('fs'); const NM = 'C:/Users/Wang Ling/.workbuddy/binaries/node/workspace/node_modules'; const puppeteer = require(path.join(NM, 'puppeteer-core')); const EDGE = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'; (async () => { const html = process.argv[2]; const outPng = process.argv[3]; const startPx = parseInt(process.argv[4] || '0', 10); const heightPx = parseInt(process.argv[5] || '1123', 10); const browser = await puppeteer.launch({ executablePath: EDGE, headless: 'new', args: ['--no-sandbox', '--allow-file-access-from-files'] }); const page = await browser.newPage(); await page.setViewport({ width: 794, height: 1123, deviceScaleFactor: 1.6 }); await page.goto('file:///' + path.resolve(html).replace(/\\/g, '/'), { waitUntil: 'load', timeout: 120000 }); const total = await page.evaluate(() => document.body.scrollHeight); await page.screenshot({ path: outPng, clip: { x: 0, y: startPx, width: 794, height: Math.min(heightPx, total - startPx) } }); console.log('html height px =', total, ' -> screenshot', outPng); await browser.close(); })().catch(e => { console.error(e); process.exit(1); });