Nellonidas
Nellonidas

Reputation: 183

Configure Puppeteer executablePath chrome in your local Windows

When I did a local development test in windows, happen was problem in executablePath.

"Failed to launch chrome! spawn /usr/bin/chromium-browser ENOENT"

I saw for windows needs to get complete path. Otherwise cannot find chrome.exe

Default in code:

const browser = await puppeteer.launch({executablePath: '/path/to/Chrome'});

In windows it worked thus:

const browser = await puppeteer.launch({executablePath: 'C:\\your_workspace\\node_modules\\puppeteer\\.local-chromium\\win64-(version)\\chrome-win\\chrome.exe'});

In visual code suggest the path

Visual Code view explorer

Upvotes: 17

Views: 68827

Answers (3)

Martijn
Martijn

Reputation: 16123

This was the fix for me on Alpine trying to get a Dockerfile to work.

Relevant bit from Dockerfile:

RUN apk add --update chromium

Relevant bit from config (copied inside the image in project root)

/**
 * @type {import("puppeteer").Configuration}
 */
module.exports = {
    executablePath: '/usr/bin/chromium',
    cacheDirectory: '/var/www/html/.cache/puppeteer', # See footnote
};

* This was needed for my build. I believe this isnt an issue if you're not doing that, but maybe it can save someone some time.
The error it fixed was Could not find Chrome (ver. 119.[...]). This can occur if either [...]

Upvotes: 0

chetbox
chetbox

Reputation: 1810

You can also set the environment variable PUPPETEER_EXECUTABLE_PATH.

This is useful in conjunction with PUPPETEER_SKIP_CHROMIUM_DOWNLOAD set to true

Upvotes: 14

Saša M
Saša M

Reputation: 126

Maybe this can help:

const osPlatform = os.platform(); // possible values are: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
console.log('Scraper running on platform: ', osPlatform);
let executablePath;
if (/^win/i.test(osPlatform)) {
  executablePath = '';
} else if (/^linux/i.test(osPlatform)) {
  executablePath = '/usr/bin/google-chrome';
}

Upvotes: 11

Related Questions