23

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.

1
  • Please share your package.json and OS.
    – ggorlen
    Oct 30, 2022 at 18:28

2 Answers 2

41

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',
  });
}
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.
    – Fabian S.
    Nov 14, 2022 at 15:33
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.