Error: Failed to launch the browser process puppeteer
Asked Answered
S

33

97

checked failed crashForExceptionInNonABIComplianceCodeRange the code below its functon is to create PDF file

   (async function() {

      try {

      const browser = await puppeteer.launch();
      const page = await browser.newPage();

      await page.setContent(pdfOutput);
      await page.emulateMedia("screen");
      await page.pdf({
        path: "routes/planiton/pdf/mypdf.pdf",
        format: "A4",
        printBackground: true
      });

      console.log('done');
      await browser.close();
      //process.exit();

    } catch (e) {
      console.log("Our Error", e)
    }
  })();
Stealage answered 30/1, 2020 at 4:42 Comment(1)
github.com/puppeteer/puppeteer/issues/… worked for me. I couldn't succeed in installing chromium-browser in my docker.Notify
D
141

I had the same issue, I tried everything which is listed from the Puppeteer guide, none of them worked for me.

What works for me was to download chromium manually sudo apt-get install chromium-browser.

And then, tell Puppeteer where chromium is located :

const browser = await puppeteer.launch({
  executablePath: '/usr/bin/chromium-browser'
})

Hope this will help someone :)

Dorinedorion answered 28/7, 2020 at 15:13 Comment(9)
Works on Mac OS X too. brew install chromium && which chromiumCavour
This seems necessary on alpine also, because puppeteer's chromium is using C functions that aren't available. Install on alpine: apk add chromium. Also call launch with args: ['--no-sandbox'] like other answers mention.Theodor
This Almost did the trick, I find it to be the most accurate answer. What worked for me was: let browser = await puppeteer.launch({ executablePath: '/usr/bin/chromium-browser', args: [ '--disable-gpu', '--disable-setuid-sandbox', '--no-sandbox', '--no-zygote' ] }) Alternate solution might be to install all dependencies as mentioned in other comments. For the most accurate list I suggest to look here:: github.com/puppeteer/puppeteer/blob/main/docs/…As
For me, I only had to install chromium using apt-get but I didn't actually have to use that version. After installing it, the embedded chromium that comes with puppeteer started to work. I guess it was missing some system libraries that were installed with apt-get.Pabulum
If you get this error while deploying on Heroku and are also using subdirectories, the buildpack order matters. The only order that worked for me was 1. https://github.com/timanovsky/subdir-heroku-buildpack, then 2. https://github.com/jontewks/puppeteer-heroku-buildpack, then 3. heroku/nodejs.Thumbstall
My Puppeteer script was working on windows but not on my raspberry pi. Adding this argument made it work!Parcae
For debian I had to run apt-get install chromium -yCohin
We have installed some Linux-based packages on the EC2 instance, but finally, PDF generation is working. browser = await puppeteer.launch({ executablePath: '/usr/bin/chromium-browser', args: [ '--disable-gpu', '--disable-setuid-sandbox', '--no-sandbox', '--no-zygote' ] })Slowpoke
You saved my life! Work well on Plesk/CentOS v7Delinda
G
21
const browser = await puppeteer.launch({
    headless:false,
    args: ["--no-sandbox"]
});

install puppeteer and puppeteer-core.

Gulgee answered 17/4, 2020 at 18:51 Comment(3)
alternative to this answer and worked for me you may use this: { headless: true, args: ["--no-sandbox", "--disable-setuid-sandbox"]}Jud
check this link github.com/puppeteer/puppeteer/blob/main/docs/…Jud
yes, args: [ '--no-sandbox' ] worked for me on ubuntu linux 22.04Hothead
F
21
apt-get install chromium-browser

Try with this command and still you get any error .

Then install some incomplete packages of the os. For Ubuntu I installed:

sudo apt-get install gconf-service 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 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 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
Frightful answered 29/12, 2020 at 18:35 Comment(1)
This worked for me I believe the issue is related to the missing Debian packages as stated on the issue reported on the puppeteer GitHub github.com/puppeteer/puppeteer/issues/807Jacquard
A
15

-On Linux (Ubuntu)V20 -using Node v12.X -using Puppeteer-core v10.0.0

https://pptr.dev/#?product=Puppeteer&version=v10.0.0&show=api-class-browserfetcher https://openbase.com/js/puppeteer-core/versions#10.0.0 -- for r[Version]

puppeteer = require('puppeteer-core');
// console.log('TRYING TO FETCH BROWSER')
const browserFetcher = puppeteer.createBrowserFetcher();
let revisionInfo = await browserFetcher.download('884014');


browser = await puppeteer.launch(
  {
    executablePath: revisionInfo.executablePath,
    args: ['--no-sandbox', "--disabled-setupid-sandbox"]
  }
)

you might get an error on a server if your running as Root and you did not set the --no-sandbox flag

if you get error like:

/home/[xxx]/[xxx]/node_modules/puppeteer[-core]/.local-chromium/linux-[xxx]/chrome-linux/chrome: error while loading shared libraries: xxxx-xxxx.xx.x: cannot open shared object file: No such file or directory

on your shell, cd to /home/[xxx]/[xxx]/node_modules/puppeteer[-core]/.local-chromium/linux-[xxx]/chrome-linux/chrome, check missing dependencies with => ldd chrome | grep not

if you get a list then run the following commands

apt-get upgrade
apt-get update
apt-get install gconf-service 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 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 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

apt-get install -y libgbm-dev
apt-get install libglib2.0-0

if the dependencies are gone then your puppeteer should work fine

Alchemize answered 14/6, 2021 at 23:44 Comment(2)
using puppeteer-core instead of puppeteer saved my life. Been facing issue since 2-3 days... Thanks mann!!Somerset
Thanks using with puppeteer, worked for me and incuding await in asynch functionsUrsal
B
9

Seems like there is a different solution for everyone. None of these worked for me, but I got it working at the end on Ubuntu 20.04 with this:

  const browser = await puppeteer.launch({
    args: ["--no-sandbox", "--disabled-setupid-sandbox"],
  });
Brandonbrandt answered 13/2, 2021 at 3:42 Comment(1)
best answer "--no-sandbox" ! thanks (debian 10)Ambrosine
S
6
const browser = await puppeteer.launch({ignoreDefaultArgs: ['--disable-extensions']});
Stealage answered 30/1, 2020 at 4:42 Comment(1)
Explain the reasonMetonym
C
6

Before starting puppeteer execute the next lines:

sudo apt-get update
sudo apt-get install -y libgbm-dev
sudo apt install -y gconf-service 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 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 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

Then execute npm start (or whatever you have) and will work.

Cystine answered 29/3, 2021 at 10:3 Comment(0)
G
5

if you get Failed to launch the browser process it possible that you didn't install chromium

sudo apt-get install chromium-browser

and then setting up

Gulgee answered 17/4, 2020 at 18:38 Comment(1)
In a docker image this worked for me apt-get install chromiumBeebread
K
5

On Debian 9.5 I had the same issue namely

Error: Failed to launch the browser process! spawn /home/user/PuppeteerTests/node_modules/puppeteer/.local-chromium/linux-737027/chrome-linux/chrome ENOENT

So I first went into node_modules/puppeteer/.local-chromium/linux-737027/ and found a zip file named chrome-linux.zip containing a folder named chrome-linux.

Then I went one directory deeper in chrome-linux and only found libGLESv2.so.

So I took the chrome-linux dir within the zip file and pasted it in node_modules/puppeteer/.local-chromium/linux-737027/ (so removed the old one).

Then I tried the example from Google :

const puppeteer = require('puppeteer');

 (async() => {
 const browser = await puppeteer.launch();
 console.log(await browser.version());
 await browser.close();
 })();

which yielded in

Error: Failed to launch the browser process!
[0424/110706.119517:FATAL:zygote_host_impl_linux.cc(116)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.

Finally following this Puppeteer guide I enabled user namespace cloning to get the sandbox working :

sudo sysctl -w kernel.unprivileged_userns_clone=1

Tried again the same example which worked.

Kindergartner answered 24/4, 2020 at 9:26 Comment(0)
D
5

The only way that works for me ( I'm using wsl for windows ) is setting the args configurations like so:

const browser = await puppeteer.launch({
    args: [
        '--disable-gpu',
        '--disable-dev-shm-usage',
        '--disable-setuid-sandbox',
        '--no-first-run',
        '--no-sandbox',
        '--no-zygote',
        '--single-process',
    ]
});
Delladelle answered 9/3, 2021 at 14:47 Comment(0)
P
5

I was facing the same issue in puppeteer when running my project on the Ubuntu server and here's how I fixed it.

1- First install Chromium if you haven't already installed

sudo apt-get install chromium-browser

2- Find out the path of Chromium by running the below command in your Ubuntu terminal.

which chromium-browser

3- Add that path to the puppeteer.

const browser: puppeteer.Browser = await puppeteer.launch({
  executablePath: '/usr/bin/chromium-browser', <-------
  }); 

4- Also add ignoreDefaultArgs: ['--disable-extensions'] to puppeteer.

const browser: puppeteer.Browser = await puppeteer.launch({
 executablePath: '/usr/bin/chromium-browser',

 ignoreDefaultArgs: ['--disable-extensions'] <----
 });
Pentheas answered 7/9, 2022 at 9:5 Comment(0)
M
3

I had the issue on a Mac - I was getting

Failed to launch the browser process! spawn /PATH/TO/node_modules/puppeteer/ \
.local-chromium/mac-756035/chrome-mac/Chromium.app/Contents/MacOS/Chromium \
ENOENT

In the end the issue was that the chromium zip didn't unzip properly. I cd'ed into node_modules/puppeteer/.local-chromium, found the zip there, unzipped it manually, and copied it to mac-756035/chrome-mac/Chromium.app/Contents/MacOS/. Then it worked as expected

Malemute answered 14/6, 2020 at 13:54 Comment(0)
H
3

Sometimes your userDataDir could have been contaminated from your other tests or codes. Just try to rename it.

 const browser = await puppeteer.launch({
    headless: false,
    userDataDir: "./user_data2",

  
  });
Huldahuldah answered 27/3, 2021 at 4:55 Comment(0)
P
3

This error can also happen if you try tu run puppeteer from an ssh console with { headless: false } option.

Pottage answered 18/6, 2021 at 13:28 Comment(0)
F
3

It work for me download sudo apt-get install chromium-browser and then

   const browser = await puppeteer.launch({
     args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu"],
     ignoreDefaultArgs: ["--disable-extensions"],
     slowMo: 100,
     // headless: false,
  });
Furr answered 8/10, 2021 at 4:30 Comment(0)
H
3

I have the same problem in gitpod and this helped me:

sudo apt update &&
sudo apt install -y libgbm-dev chromium-browser gconf-service 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 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 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
Hesitancy answered 18/8, 2022 at 4:45 Comment(0)
U
3

I'm using M1 Mac, I have the same problem and these steps helped me resolve:

  • Install chromium with brew
brew install chromium
  • Get chromium path
which chromium 

=> /opt/homebrew/bin/chromium

  • Apply chromium path for config
puppeteer.launch({
    ...
    executablePath: '/opt/homebrew/bin/chromium',
  });

Make sure chromium can run in your device, you can get error when open Chromium “Chromium.app” is damaged and can’t be opened. You should move it to the Trash. => Resolve by this: xattr -cr /Applications/Chromium.app

Upstanding answered 20/2, 2023 at 7:12 Comment(0)
A
2

I had the same problem and the gurus out there will tell you bunch of things. Just add

const browser = await puppeteer.launch({headless: false}); // default is true
Altaf answered 30/1, 2020 at 5:13 Comment(1)
headless=true leads to an opened browser on server.Braca
B
2

For windows users, follow this step can help you :

-download chrominium here https://download-chromium.appspot.com/

-dezip the file

-in node_modules/puppeteer/.local-chrominium/win64-869685/ , replace the chrome-win file by the one you dowloaded.

Barbabra answered 15/5, 2021 at 19:6 Comment(0)
I
2

I just solved the error with this. Just edit the the next line as this:

const browser = await puppeteer.launch({ignoreDefaultArgs: ['--disable-extensions']});

and tell puppeteer where is your browser located.

Now my code looks like this and worked succesfully:

const browser: puppeteer.Browser = await puppeteer.launch({
  executablePath: '/usr/bin/chromium-browser',
  ...,
  ignoreDefaultArgs: ['--disable-extensions']
});
Insouciant answered 22/5, 2021 at 23:46 Comment(1)
I want to emphasize that the executable path includes the executable file not just the directory the contains the file (I misunderstood this).Phrenology
F
2

This worked for me

 let browser = await puppeteer.launch({ executablePath: '/usr/bin/chromium-browser', args: [ '--disable-gpu', '--disable-setuid-sandbox', '--no-sandbox', '--no-zygote' ] })
Faction answered 19/12, 2023 at 7:19 Comment(0)
A
1

The following did the job for me (Mac OS):

  • Downgraded to NodeJS v12 (previously I had v14)
  • reinstalled dependencies
Aquarius answered 30/8, 2021 at 8:39 Comment(0)
S
1

You can set the "executablePath" via Environment-Variable:

export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
Selfreliant answered 22/12, 2022 at 11:1 Comment(0)
S
1

If you are experiencing this issue on the server, you can add this script to your pipeline

RUN apt-get update  && \
apt-get install -y libglib2.0-0 libgbm1 libasound2 libatk-bridge2.0-0 libgtk-3-0 libnspr4 libnss3 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6

this will install all puppeteer dependencies

Saucy answered 12/4, 2023 at 11:20 Comment(0)
A
1

This worked for me:

executablePath: puppeteer.executablePath()
Acceptation answered 19/6, 2023 at 18:31 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Potheen
T
0

Use this:

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

And need to install some dependencies on the serve. https://github.com/puppeteer/puppeteer/issues/5662?fbclid=IwAR17HxYebtc14UvptAAUUk7qd4oMTysm-Uasv7KBm1LN7aN2H7GAkj6IxIU#issuecomment-732076246

Thrifty answered 1/7, 2022 at 5:18 Comment(0)
M
0

For me an issue was due to I was running puppeteer.launch(..) on every request. I start the browser once and reuse the same instance; post that it works fine.

Miculek answered 5/8, 2022 at 11:29 Comment(0)
E
0

It's very important to check version compability between chromium installed manually and puppeter version:

https://pptr.dev/chromium-support

Evade answered 29/3, 2023 at 7:15 Comment(0)
R
0

deleting SingeltonLock file from the directory where you save user data worked for me.

Rig answered 21/6, 2023 at 19:55 Comment(0)
D
0

Use this as it works for me on Ubuntu by adding the path to your google-chrome or any broswer of your choice and then setting headless to false to enable the browser GUI:

const browser = await puppeteer.launch({executablePath: '/usr/bin/google-chrome', headless: false});
    const page = await browser.newPage();
Darra answered 24/7, 2023 at 14:25 Comment(0)
I
0

I had a similar problem, but after installing all the dependencies mentioned in the 'puppeteer' GitHub repository, the issue was resolved.

Here is the link:

https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-doesnt-launch-on-linux

Ind answered 3/9, 2023 at 9:30 Comment(0)
P
0

When I was inside the VDS, I used the following parameters in puppeteer.launch:

const browser = wait puppeteer.launch({
    headless: cfg.buildType === 'LOCAL' && process.env.DEBUG === "true" ? false : true,
    args: ["--disable-notifications", "--disable-geolocation", '--no-sandbox'],
    product: process.env.BROWSER as product,
    ...(cfg.buildType === 'PRODUCTION' && {executablePath: '/usr/bin/chromium-browser'}),
  })

and every time I started the browser I got the error:

Error: Failed to launch the browser process!
Sorry, home directories outside of /home are not currently supported.
See https://forum.snapcraft.io/t/11209 for details.

Afterwards, I changed the parameters:

const browser = await puppeteer.launch({
    headless: cfg.buildType === 'LOCAL' &&process.env.DEBUG === "true" ? false : true,
    args: ["--no-sandbox", "--disable-notifications", "--disable-geolocation"],
    product: process.env.BROWSER as product,
  })

and for my case it helped. Before the working option I installed depends from https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md and sudo apt-get install chromium-browser

Platinumblond answered 20/10, 2023 at 11:29 Comment(0)
S
0

After install the chromium browser and it went into the snap folder so the pupeeteer code:

const browser = await puppeteer.launch({
  headless: "new", // Recommended: The new method
  executablePath: "/snap/bin/chromium",
});
Selfidentity answered 3/11, 2023 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.