如何为 Puppeteer 设置 --shm-size 配置

How to set --shm-size configuration for Puppeteer

我遇到了与 this 线程中相同的错误。解决方法是设置--shm-size=1gb。 从 Puppeteer 文档中,我发现了以下注释:

By default, Docker runs a container with a `/dev/shm` shared memory space 64MB.
This is [typically too small](https://github.com/c0b/chrome-in-docker/issues/1) for Chrome 
and will cause Chrome to crash when rendering large pages. To fix, run the container
with `docker run --shm-size=1gb` to increase the size of `/dev/shm`. Since Chrome 65, 
this is no longer necessary. Instead, launch the browser with the `--disable-dev-shm-usage` 
flag

我尝试了以下代码但没有成功:

const args = [`--app=${url}`, `--window-size=${WIDTH},${HEIGHT}`, '--disable-dev-shm-usage'];
const browser = await puppeteer.launch({
    headless,
    args
});

如何正确设置 Puppeteer 的 --shm-size?

Node version: 8.9.3
Platform: Windows 10

Puppeteer 函数 puppeteer.launch() allows for an optional options object

对象有名称(或)和关联值。

因此,为了将 Chromium 标志传递给 puppeteer.launch(),您必须使用 args 键和包含相关标志的数组值:

const browser = await puppeteer.launch({
  args: [
    '--disable-dev-shm-usage',
  ],
});

在您的示例中,您传递的数组没有 args 键。