Reputation: 91
I am trying to hit an api which uses puppeteer, it basically has a function that fetches me discord users, not very well versed with puppeteer so mind my lack of explanation, did some research and found some solution as installing chromium manually, did that, running the puppeteer to run chromium with headless still no luck it prompts me with Command '/usr/bin/chromium-browser' requires the chromium snap to be installed, I am using WSL to run this and seems like it's not really supported with WSL,
const browser = await puppeteer.launch({
//only for testing
headless: true,
// for testing at - ibad
executablePath: '/usr/bin/chromium-browser',
args: [
'--no-sandbox',
'--start-maximized'
],
ignoreHTTPSErrors: true
});
this is the launch code for puppeteer, the message that I get in the api response:
"message": "Failed to launch the browser process!\n\nCommand '/usr/bin/chromium-browser' requires the chromium snap to be installed.\nPlease install it with:\n\nsnap install chromium\n\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n",,
any help would be appreciated, new to this puppeteer stuff thanks!
Upvotes: 9
Views: 8346
Reputation: 476
If using Option 2 (above), it worked on WSL2 by setting the executablePath
attribute to google-chrome
. You must install full Google Chrome with:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
const puppeteer = require('puppeteer-core');
async function scrapeWebData(url, selector, callback, headless){
if(headless === undefined){
headless = true;
}
const browser = await puppeteer.launch({
executablePath: '/usr/bin/google-chrome-stable',
headless: headless
});
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(0);
const res = await page.goto(url);
const status = res.status();
if(status != 200){
throw new Error(`The URL at '${url}' was not found.`);
}
const results = await page.$$eval(selector, callback);
await browser.close();
if(results === undefined || results.length === 0) {
throw new Error('The CSS selector returned 0 results.');
}
return results;
}
Upvotes: 0
Reputation: 20820
Systemd (and, as a result, Snap) is now supported on WSL. See this Community Wiki answer or my original answer on Ask Ubuntu for information on how to enable.
Based on the recent WSL changes, for Chromium on Ubuntu, in particular, you have several options:
Option 1: Enable Systemd and Snap functionality on Ubuntu in WSL per the link above.
Option 2: Install without using the Snap. See this Ask Ubuntu question for some different ways to do so.
Option 3: Use Google Chrome (or other), rather than Chromium
I've had no issue using chromedriver with Google Chrome on Ubuntu with Selenium. It's been about two years since I used Puppeteer (pre-WSLg), but I was able to do that as well on WSL2.
If you want to use a non-Google Chromium-based browser, then Brave and Vivaldi (and probably others) are candidates. From previous research, IIRC, both provide webdrivers.
Option 4: Use a non-Systemd distribution under WSL2. I've been able to install and run Chromium/chromedriver successfully on Artix Linux under WSL2 and use it with Selenium. That's probably not a newbie friendly task, however, but I'll throw it out as a possibility anyway.
Upvotes: 2