Error while launching headless browser using puppeteer. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Error while launching headless browser using puppeteer.

Why I am getting error :failed to launch browser ? Here is the script const puppeteer=require("puppeteer"); (async () => { const browser = await puppeteer.launch({ executablePath:'/usr/bin/chromium-browser'}); const page = await browser.newPage() await page.goto('https://something.com/') await page.hover('.something') await page.screenshot({ path: 'hover.png' }) await browser.close() })()

10th Jan 2021, 10:19 PM
Abhay
Abhay - avatar
6 Answers
+ 2
If you run this in your terminal, does the browser open? /usr/bin/chromium-browser I wonder if your browser is installed in another path on your machine. If that doesn't identify the problem, have you tried many of the suggestions discussed below? https://stackoverflow.com/questions/59979188/error-failed-to-launch-the-browser-process-puppeteer
12th Jan 2021, 7:01 PM
Josh Greig
Josh Greig - avatar
+ 2
Josh Greig ty for response,but I have tried all that .And I am not sure if the path i have placed is right or not but here is my directory structure usr bin chromium-browser ~ puppet index.js (contains all that code given in description) also I am using node version 12.20.1 ,but I have deleted that and gonna check with latest version to see if that was the problem.
13th Jan 2021, 10:41 AM
Abhay
Abhay - avatar
+ 2
Josh Greig I am experimenting new things ,nothing like I have a specific requirement but I do like to code mostly on my android device ,so I thought why not try looking for a solution to it .And actually I came across a GitHub issue where people were able to run this successfully , although for me I was getting segmentation fault errors .And from there it's been a mess and I just can't figure out anything but thank you as you are right about asking a seperate question for installation of chromium on android ,ty for your time!
14th Jan 2021, 5:11 PM
Abhay
Abhay - avatar
+ 1
Does Chromium open if you run this in a terminal? /usr/bin/chromium-browser
13th Jan 2021, 6:13 PM
Josh Greig
Josh Greig - avatar
+ 1
Josh Greig whenever I do that It says to install chromium snap but when I proceed to do so I get error error: cannot communicate with server: Post http://localhost/v2/snaps/chromium: dial unix /run/snapd.socket: connect: no such file or directory : Also I have been trying to do all this inside a ubuntu os installed using termux app on my android device (as I can't run puppeteer on android device) which has been troublesome for me .
13th Jan 2021, 9:12 PM
Abhay
Abhay - avatar
+ 1
That's your more specific problem then. nodejs can't launch a browser that isn't even installed. This is what I suspected from my first answer. You're trying to do all this in an Android device? Why not run it in a PC or a more conventional server instead? I've never ran nodejs or puppeteer on an Android device but it is simple enough with Ubuntu. What are you ultimately trying to do? You want screenshots of a website exactly how it looks in an Android phone? If you have strong requirements to get this working in Android, it could help to ask a new question that is specifically related to how to install Chromium on Android and control it through puppeteer. I controlled Chrome through puppeteer in Ubuntu but can't help much with Android.
14th Jan 2021, 5:42 AM
Josh Greig
Josh Greig - avatar