'Failed to launch the browser process!/usr/bin/chromium-browser' requires the chromium snap to be installed

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!



Solution 1:[1]

Yes, Systemd (and, as a result, Snap) is not directly supported on WSL without additional effort. I go into a lot more detail on the Systemd issues and possible workarounds in this Ask Ubuntu answer. It's quite long, so I won't repeat it here in full.

To summarize, Systemd requires that it be running as PID1 for most of its functionality to work. Since WSL's own /init process runs as PID1, Systemd doesn't "play nice" with WSL (and vice versa).

For Chromium on Ubuntu, in particular, you have several options:

  • Option 1: Install without using the Snap. See this Ask Ubuntu question for some different ways to do so.

  • Option 2: 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 3: 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.

  • Option 4: Get Systemd running on WSL/Ubuntu

    While I won't go through all the steps here, there are a number of Systemd helpers out there for WSL, including Genie, distrod, and others.

    These all work the same way at their core, by using creating a new Linux PID namespace where Systemd is PID1, then putting you inside that namespace. I don't recommend it for new users, really. There are quite a few things that are changed on your WSL system, and it's best that you have a deep understanding of Systemd before using it with WSL, IMHO.

    But, it's there as an option. I believe you can install Snaps with this in place, but I haven't tried it personally.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NotTheDr01ds