81

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)
    }
  })();
Abu Dujana Mahalail
  • 1,547
  • 1
  • 8
  • 21
  • 3
    https://github.com/puppeteer/puppeteer/issues/5662#issuecomment-732076246 worked for me. I couldn't succeed in installing `chromium-browser` in my docker. – Joshua Varghese Mar 03 '21 at 07:40

30 Answers30

119

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 :)

JULIEN PICARD
  • 1,364
  • 1
  • 8
  • 11
  • 13
    Works on Mac OS X too. `brew install chromium && which chromium` – user2398029 Oct 17 '20 at 02:39
  • 3
    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. – Kelvin Aug 17 '21 at 19:54
  • 4
    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:: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md – Lior Gross Dec 30 '21 at 05:07
  • 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`. – d512 Jan 08 '22 at 15:21
  • 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`. – auphynne Jan 10 '22 at 15:46
  • My Puppeteer script was working on windows but not on my raspberry pi. Adding this argument made it work! – Veegish Ramdani Feb 13 '22 at 07:25
  • For debian I had to run `apt-get install chromium -y` – Morfinismo Jul 25 '22 at 22:02
  • 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' ] })``` – kusama Oct 15 '22 at 12:46
  • You saved my life! Work well on Plesk/CentOS v7 – Mavichow Feb 21 '23 at 03:38
20
const browser = await puppeteer.launch({
    headless:false,
    args: ["--no-sandbox"]
});

install puppeteer and puppeteer-core.

  • alternative to this answer and worked for me you may use this: { headless: true, args: ["--no-sandbox", "--disable-setuid-sandbox"]} – Safwat Fathi Oct 28 '20 at 12:54
  • check this link https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#setting-up-chrome-linux-sandbox – Safwat Fathi Oct 28 '20 at 12:55
  • yes, args: [ '--no-sandbox' ] worked for me on ubuntu linux 22.04 – Theo Jul 27 '22 at 12:54
19
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
Nathan Chu
  • 635
  • 1
  • 3
  • 19
  • 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 https://github.com/puppeteer/puppeteer/issues/807 – Emmanuel Neni Aug 20 '21 at 12:26
14

-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

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"],
  });
Dharman
  • 30,962
  • 25
  • 85
  • 135
Smlok
  • 598
  • 6
  • 19
6
const browser = await puppeteer.launch({ignoreDefaultArgs: ['--disable-extensions']});
Nadeem0035
  • 3,757
  • 1
  • 24
  • 36
Abu Dujana Mahalail
  • 1,547
  • 1
  • 8
  • 21
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.

HelloWorld
  • 2,275
  • 18
  • 29
5

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.

Peter Palmer
  • 726
  • 11
  • 18
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'] <----
 });
Muhammad Haidar
  • 1,541
  • 16
  • 17
4

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

4

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',
    ]
});
Dr4kk0nnys
  • 697
  • 7
  • 13
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

gotofritz
  • 3,341
  • 1
  • 31
  • 47
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",

  
  });
goodhyun
  • 4,814
  • 3
  • 33
  • 25
3

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

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Josep Alsina
  • 2,762
  • 1
  • 16
  • 12
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,
  });
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
Ernesto
  • 3,944
  • 1
  • 14
  • 29
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.

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']
});
CxrlosKenobi
  • 94
  • 1
  • 6
2

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
FreePhoenix888
  • 4,510
  • 3
  • 13
  • 22
2

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

1

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

  • Downgraded to NodeJS v12 (previously I had v14)
  • reinstalled dependencies
Matthew Barbara
  • 3,792
  • 2
  • 21
  • 32
1

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

export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
Benjamin
  • 11
  • 1
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

Austin
  • 364
  • 1
  • 9
  • 21
1

This worked for me:

executablePath: puppeteer.executablePath()
  • 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. – DSDmark Jun 26 '23 at 03:20
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

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.

sham
  • 422
  • 4
  • 18
0

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

https://pptr.dev/chromium-support

alex
  • 1
0

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

Nayla
  • 1
  • 2
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();
David MD
  • 39
  • 3
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