Running headless Chrome / Puppeteer with --no-sandbox

后端 未结 4 1776
青春惊慌失措
青春惊慌失措 2020-12-16 04:02

Background

I built an application that uses Puppeteer on my localhost. Now that I am trying to deploy it into a debian environment the script that r

相关标签:
4条回答
  • 2020-12-16 04:30

    There is no need of a timeout,

    const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});

    0 讨论(0)
  • 2020-12-16 04:32

    I was hitting a similar problem trying to run Chromium headless in an Alpine Docker container, and apparently so are many other (e.g., here, here). The --no-sandbox option is a straightforward workaround but obviously a poor security practice. What worked for me was setting a custom seccomp.

    Download this file (if interested, see the author's notes here). Then pass the option --security-opt seccomp=path/to/chrome.json when starting Docker, or specify the same option in your docker-compose.yml if you're using one.

    0 讨论(0)
  • 2020-12-16 04:36

    In your nodejs code when you launch your browser, you can pass the --no-sandbox argument.

    example:-

    const launchBrowser = async () => {
      puppetBrowser = await puppeteer.launch({
        args: ['--no-sandbox'],
        timeout: 10000,
      });
    };
    
    0 讨论(0)
  • 2020-12-16 04:39

    Background

    I was the OP. Months have went by and I continue to see people having similar problems all over the internet. Github issues and SO. Due to that I want to show everyone how I solved this issue.

    Problem

    Running Puppeteer on Debian fails due to missing libs.

    Solution

    I was able to run the application using a Docker file and adding a config option to Puppeteer.

    Examples

    Docker File

    FROM node:8
    ENV HOST 0.0.0.0
    EXPOSE 8080
    RUN apt-get update
    
    # for https
    RUN apt-get install -yyq ca-certificates
    # install libraries
    RUN apt-get install -yyq libappindicator1 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
    # tools
    RUN apt-get install -yyq gconf-service lsb-release wget xdg-utils
    # and fonts
    RUN apt-get install -yyq fonts-liberation
    
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    COPY . /usr/src/app
    RUN mkdir -p /usr/src/app/views
    
    # install the necessary packages
    RUN npm install
    
    CMD npm run start
    

    Puppeteer

    const browser = await puppeteer.launch({
              args: ['--no-sandbox', '--disable-setuid-sandbox'],
              ignoreHTTPSErrors: true,
              dumpio: false
            });
    

    I hope this helps. Basically when running the app you will install the missing libs by configuring your Docker file then when your app is running the config options passed to the Puppeteer object will allow your app to run on Debian.

    0 讨论(0)
提交回复
热议问题