How to Setup Puppeteer In CentOS 7


How to Setup Puppeteer in CentOS 7

Setup Puppeteer In CentOS 7 is easy but gets tricky in Linux distributions. Few weeks back we have Completed a project using puppeteer . Now the Question was Where Should we deploy ?

Our code is written in Windows and we wanted to move code to Production . Now we have CentOS 7 in prod . We were struggling to run Puppeteer on Prod machine .

Have a look at Environment details we have used to deploy a puppeteer .

Environment Details:

Have a look at Steps we Have Followed to Deploy A puppeteer backed application in CentOS 7

Step 1:- Install Node JS In CentOS 7

Step 2 :- Install Puppeteer In CentOS 7

Step 3 :- Install Chromium In CentOS 7

Step 4 :- Install puppeteer in CentOs7

Now Let’s Write a Sample Code to run Puppeteer in headless mode and name that file as test.js

Step 5 :- Run the Code , you will see the following output

Setup Puppeteer In CentOS 7
running puppeteer centos7 without sandbox mode

Real problem starts here , We are not able to launch browser without --no-sandbox flag.

I Challenge most of you will face this problem while you setup puppeteer in Centos 7. SO Follow down this simple hack to solve this . I struggled a lot , I think you may or may not . But if you have reached this section of article then i firmly believe you have faced this as well.

For running Puppeteer in sandbox mode we need to do few changes as of now .

If you navigate to node_modules/puppeteer/.local-chromium/linux-549031, you notice that for puppeteer there is a file named chrome_sandbox (with an underscore).

Renaming this file to chrome-sandbox and perform following steps below

So what are we doing here ,

We are renaming the chrome_sandbox folder to chrome-sandbox as standard chromium searches for file with chrome-sandbox. Now run the test file again.

Conclusion :-

While running puppeteer we were facing issues Unable to connect to chrome . While searching on internet about the problem i got this solution .

References :-


Please enter your comment!
Please enter your name here