小编bmi*_*rek的帖子

Puppeteer 因生成大型 pdf 而挂起

我需要使用 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: …

pdf chromium node.js google-chrome-headless puppeteer

5
推荐指数
0
解决办法
4484
查看次数