Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer: Failed to launch the browser process! spawn

When I try to run node app.js, I get error:

the message is Failed to launch the browser process! spawn /Users/iliebogdanbarbulescu/Downloads/firstProject/node_modules/chromium/lib/chromium/chrome-mac/Chromium.app

EACCES

What I did I checked the folder at /Users/iliebogdanbarbulescu/Downloads/firstProject/node_modules/chromium/lib/chromium/chrome-mac/Chromium.app and the file is not zipped. It can be run.

Note: If I try to execute without the path, it works, but I would like to use either Chrome or Chromium to open a new page. const browser = await puppeteer.launch({headless:false'});

const express = require('express');
const puppeteer = require('puppeteer');
const app = express();

(async () => {
  const browser = await puppeteer.launch({headless:false, executablePath:'/Users/iliebogdanbarbulescu/Downloads/firstProject/node_modules/chromium/lib/chromium/chrome-mac/Chromium.app'});
 const page = await browser.newPage();
 await page.goto('https://google.com', {waitUntil: 'networkidle2'});

})().catch((error) =>{
  console.error("the message is " + error.message);
});

app.listen(3000, function (){
    console.log('server started');
})

enter image description here

like image 536
bibscy Avatar asked Dec 11 '22 00:12

bibscy


1 Answers

If you navigate to chrome://version/ page in this exact browser, it will show the Executable Path which is the exact string you need to use as executablePath puppeteer launch option.

Usually, chrome's path looks like this on MAC:

/Applications/Google Chrome.app/Contents/MacOS/Google Chrome

Or something like this if chromium is located in your node_modules folder:

/Users/iliebogdanbarbulescu/Downloads/firstProject/node_modules/chromium/lib/chromium/chrome-mac/Chromium.app/Contents/MacOS/Chromium

Now if you compare the string you used for executablePath: it differs from the one retrieved with the method mentioned above. Exactly the /Contents/MacOS/Chromium should be added to the end of the current path to make it work.

Note: the chromium bundled with puppeteer is the version guaranteed to work together with the actual pptr version: if you plan to use other chrome/or chromium-based browsers you might experience unexpected issues.

like image 153
theDavidBarton Avatar answered Jan 14 '23 11:01

theDavidBarton