florin
florin

Reputation: 807

How to set --shm-size configuration for Puppeteer

I have the same error as in this thread. The solution is to set --shm-size=1gb. From the Puppeteer docs, I found the following notes:

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

I've tried the following code but with no success:

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

How to propperly set --shm-size for the Puppeteer?

Node version: 8.9.3
Platform: Windows 10

Upvotes: 4

Views: 4098

Answers (1)

Grant Miller
Grant Miller

Reputation: 29037

The Puppeteer function puppeteer.launch() allows for an optional options object.

Objects have names (or keys) and associated values.

Therefore, in order to pass Chromium flags to puppeteer.launch(), you must use the args key with an array value that contains the relevant flags:

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

In your example, you are passing the array without the args key.

Upvotes: 2

Related Questions