Abu Dujana Mahalail
Abu Dujana Mahalail

Reputation: 1901

Error: Failed to launch the browser process puppeteer

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)
    }
  })();

Upvotes: 111

Views: 360759

Answers (30)

Meaningful Life
Meaningful Life

Reputation: 28

For anyone running through this error in ubuntu24, You need to install those packages:

sudo apt-get install  libasound2t64 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgdk-pixbuf2.0-0 libglib2.0-0t64 libgtk-3-0t64 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 libnss3 lsb-release xdg-utils wget

Upvotes: 0

elfarqy
elfarqy

Reputation: 171

by default, puppeteer will bring chrome when you install them. To verify which plugin still missing, change your directory into

cd .cache/puppeteer/chrome/{version of linux}/chrome-linux64/

then run

ldd chrome | grep not

if text like this appear, you should install that library in your OS.

        libatk-bridge-2.0.so.0 => not found
        libcups.so.2 => not found
        libatspi.so.0 => not found
        libXcomposite.so.1 => not found
        libXdamage.so.1 => not found
        libXfixes.so.3 => not found
        libXrandr.so.2 => not found
        libgbm.so.1 => not found
        libpango-1.0.so.0 => not found
        libcairo.so.2 => not found
        libasound.so.2 => not found

Upvotes: 1

Will
Will

Reputation: 20191

Pulled my hair out trying every solution with Chrome and Chromium. I solved this with Firefox:

const browser = await puppeteer.launch({ browser: 'firefox' });

On this first run this may prompt you to run

npx puppeteer browsers install firefox

After that was satisfied puppeteer worked great.

Upvotes: 0

This worked for me

 let browser = await puppeteer.launch({ executablePath: '/usr/bin/chromium-browser', args: [ '--disable-gpu', '--disable-setuid-sandbox', '--no-sandbox', '--no-zygote' ] })

Upvotes: 2

Chelladurai S
Chelladurai S

Reputation: 1

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",
});

Upvotes: 0

DiZiNnEs
DiZiNnEs

Reputation: 117

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

Upvotes: 0

mohammad jafari
mohammad jafari

Reputation: 1

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

Upvotes: 0

David MD
David MD

Reputation: 87

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();

Upvotes: 0

Nayla
Nayla

Reputation: 1

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

Upvotes: 0

Harshit chadha
Harshit chadha

Reputation: 11

This worked for me:

executablePath: puppeteer.executablePath()

Upvotes: 1

FreePhoenix888
FreePhoenix888

Reputation: 6087

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

Upvotes: 6

Austin
Austin

Reputation: 414

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

Upvotes: 1

Josep Alsina
Josep Alsina

Reputation: 3027

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

Upvotes: 3

alex
alex

Reputation: 1

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

https://pptr.dev/chromium-support

Upvotes: 0

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

Upvotes: 4

Benjamin
Benjamin

Reputation: 21

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

export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser

Upvotes: 2

Muhammad Haidar
Muhammad Haidar

Reputation: 2019

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'] <----
 });

Upvotes: 7

sham
sham

Reputation: 452

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.

Upvotes: 0

Suvrajit Karmaker
Suvrajit Karmaker

Reputation: 16

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

Upvotes: 0

khoa junior
khoa junior

Reputation: 29

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,
  });

Upvotes: 3

Matthew Barbara
Matthew Barbara

Reputation: 3962

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

  • Downgraded to NodeJS v12 (previously I had v14)
  • reinstalled dependencies

Upvotes: 1

Tlotli Otlotleng
Tlotli Otlotleng

Reputation: 341

-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

Upvotes: 15

CxrlosKenobi
CxrlosKenobi

Reputation: 138

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']
});

Upvotes: 2

Barnabe Mugnier
Barnabe Mugnier

Reputation: 21

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.

Upvotes: 2

Peter Palmer
Peter Palmer

Reputation: 854

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.

Upvotes: 6

goodhyun
goodhyun

Reputation: 5002

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",

  
  });

Upvotes: 3

Dr4kk0nnys
Dr4kk0nnys

Reputation: 767

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',
    ]
});

Upvotes: 5

Smlok
Smlok

Reputation: 658

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"],
  });

Upvotes: 11

Rajendra singh rana
Rajendra singh rana

Reputation: 461

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

Upvotes: 27

JULIEN PICARD
JULIEN PICARD

Reputation: 1832

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

Upvotes: 165

Related Questions