我需要使用 puppeteer/chromium 生成 2000 多个页面,从 html 到 pdf。
目前,我有以下配置:
浏览器.js:
const p = require("puppeteer");
const isLinux = process.platform === "linux";
const LINUX_CHROMIUM = "/usr/bin/chromium-browser";
const WINDOWS_CHROME = `C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe`;
module.exports = async ({ port, host }) => {
const options = isLinux
? {
headless: true,
executablePath: LINUX_CHROMIUM,
args: [
"--no-sandbox",
"--disable-gpu",
"--window-size=1200,1200",
"--disable-dev-shm-usage",
"--unlimited-storage",
"--full-memory-crash-report"
],
userDataDir: "/usr/cache",
}
: {
headless: true,
executablePath: WINDOWS_CHROME,
args: [
"--window-size=1200,1200",
"--disable-dev-shm-usage",
"--unlimited-storage",
"--full-memory-crash-report"
],
};
return await p.launch(options);
}
Run Code Online (Sandbox Code Playgroud)
服务器.js: …