使用 Chrome + puppeteer-core 对 HTML 文件进行整页截图并保存为 PNG 图片,无需下载浏览器。适用场景:①渲染数据可视化...
Converts HTML files to PNG screenshots (or PDF documents) using the system's installed Chrome via puppeteer-core.
/Applications/Google Chrome.app/Contents/MacOS/Google Chromenpm install -g puppeteer-corescripts/screenshot.sh#text
scripts/screenshot.sh <html-file> [output-path] [width]
html-file: Path to the HTML file (required)output-path: Output PNG path (default: /tmp/screenshot.png)width: Viewport width in px (default: 420, good for mobile/微信)The script:
bash
bash scripts/screenshot.sh /path/to/report.html /tmp/output.png 420
Then send the image via the message tool:
json
{
"action": "send",
"media": "/tmp/output.png",
"message": "📊 Report Title"
}
Chrome's print-to-PDF can generate PDFs instead:
bash
bash scripts/screenshot.sh /path/to/report.html /tmp/output.pdf 420
http.server. Make sure python3 is available.