Puppeteer error: An `executablePath` or `channel` must be specified for `puppeteer-core`
Asked Answered
H

3

24

I'm trying to make a simple Puppeteer project. My current code is just a test. It doesn't work though.

import bypass from './captcha/captchaBypasser.js';
import {createRequire} from "module";

const require = createRequire(import.meta.url);

const puppeteer = require('puppeteer-extra');
const hidden = require('puppeteer-extra-plugin-stealth')

test()

async function test() {

  // Launch sequence
  puppeteer.use(hidden())
  const browser = await puppeteer.launch({
    args: ['--no-sandbox',],
    headless: false,
    ignoreHTTPSErrors: true
  })

  const page = await browser.newPage()
  await page.setViewport({
    width: 1920,
    height: 1280,
    deviceScaleFactor: 1,
  });

  //Go to page
  await page.goto('https://google.com/', {
    waitUntil: 'networkidle0',
  });
}

I searched around for an explanation but it seems like I am the only one getting this error

        throw new Error(message);
              ^

Error: An `executablePath` or `channel` must be specified for `puppeteer-core`
    at assert (C:\Users\Julian\Desktop\project\node_modules\puppeteer-core\lib\cjs\puppeteer\util\assert.js:28:15)
    at ChromeLauncher.launch (C:\Users\Julian\Desktop\project\node_modules\puppeteer-core\lib\cjs\puppeteer\node\ChromeLauncher.js:69:36)
    at PuppeteerNode.launch (C:\Users\Julian\Desktop\project\node_modules\puppeteer-core\lib\cjs\puppeteer\node\PuppeteerNode.js:154:105)
    at PuppeteerExtra.launch (C:\Users\Julian\Desktop\project\node_modules\puppeteer-extra\dist\index.cjs.js:128:41)
    at async test (file:///C:/Users/Julian/Desktop/project/test.js:21:19)

Node.js v18.12.0

I was expecting a Puppeteer instance to pop up and go to google.com. Instead, I got an error.

Haldis answered 30/10, 2022 at 9:29 Comment(1)
Please share your package.json and OS.Hirz
P
45

It seems like puppeteer-core now requires executablePath as mandatory.

Try this:

import bypass from './captcha/captchaBypasser.js';

import {createRequire} from "module";
const require = createRequire(import.meta.url);

const puppeteer = require('puppeteer-extra');
const hidden = require('puppeteer-extra-plugin-stealth')

// require executablePath from puppeteer
const {executablePath} = require('puppeteer')

test()

async function test() {

  // Launch sequence
  puppeteer.use(hidden())
  const browser = await puppeteer.launch({
    args: ['--no-sandbox',],
    headless: false,
    ignoreHTTPSErrors: true,

    // add this
    executablePath: executablePath(),
  })

  const page = await browser.newPage()
  await page.setViewport({
    width: 1920,
    height: 1280,
    deviceScaleFactor: 1,
  });

  // Go to page
  await page.goto('https://google.com/', {
    waitUntil: 'networkidle0',
  });
}
Palecek answered 31/10, 2022 at 5:23 Comment(1)
using the executablePath required from the puppeteer caused a typescript error for me: TS2322: Type '(channel?: ChromeReleaseChannel) => string' is not assignable to type 'string'. Im using the executeablePath from the PUPPETEER_EXECUTABLE_PATH env directly now and it works fine.Bargeboard
A
3

I think this is a new issue. My previously working code is now receiving the same error after updating my puppeteer version. Try re-installing an older version of puppeteer, or it could need an older version of node.js.

Ashaashamed answered 31/10, 2022 at 1:17 Comment(0)
L
0

The issue is because of the update to puppeteer-core.

Puppeteer-core does not come with a chromium install, so you have to manually set the path.

I found that to make things easier, you're better off just using puppeteer instead of puppeteer-core.

npm install puppeteer

then import puppeteer from 'puppeteer'

Lastditch answered 14/7, 2024 at 21:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.