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

时间:2018-01-15 13:15:39

标签: node.js 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

1 个答案:

答案 0 :(得分:1)

Puppeteer函数puppeteer.launch()允许使用可选的options object

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

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

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

在您的示例中,您传递的是不带args键的数组。