berstend / puppeteer-extra

💯 Teach puppeteer new tricks through plugins.
https://extra.community
MIT License
6.37k stars 736 forks source link

[Bug] Error: An `executablePath` or `channel` must be specified for `puppeteer-core` #730

Open oom- opened 1 year ago

oom- commented 1 year ago

Describe the bug

  1. Fresh installation with : npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth

  2. Copy paste the main from puppeteer-extra-plugin-stealth npm

  3. Start the program with node index.js

  4. I get the error Error: An 'executablePath' or 'channel' must be specified for 'puppeteer-core': image

Code Snippet

// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('puppeteer-extra');

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());

// puppeteer usage as normal
puppeteer.launch({ headless: true }).then(async browser => {
  console.log('Running tests..')
  const page = await browser.newPage()
  await page.goto('https://bot.sannysoft.com')
  await page.waitForTimeout(5000)
  await page.screenshot({ path: 'testresult.png', fullPage: true })
  await browser.close()
  console.log(`All done, check the screenshot. ✨`)
});

Versions

  System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
    Memory: 8.58 GB / 15.95 GB
  Binaries:
    Node: 16.13.2 - D:\Program Files\nodejs\node.EXE
    npm: 8.1.2 - D:\Program Files\nodejs\npm.CMD
  npmPackages:
    puppeteer: ^19.1.0 => 19.1.0
    puppeteer-extra: ^3.3.4 => 3.3.4
    puppeteer-extra-plugin-stealth: ^2.11.1 => 2.11.1

=================================== Edit So it seems that puppeteer-core require now the executablePath as mandatory? I think this is new I never got this error before.

I fixed it by adding the path to the chrome.exe file:

const os = require("os");
// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('puppeteer-extra');

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());

// puppeteer usage as normal
puppeteer.launch({ headless: true, executablePath: `${os.homedir()}/.cache/puppeteer/chrome/win64-1045629/chrome-win/chrome.exe`}).then(async browser => {
  console.log('Running tests..')
  const page = await browser.newPage()
  await page.goto('https://bot.sannysoft.com')
  await page.waitForTimeout(5000)
  await page.screenshot({ path: 'testresult.png', fullPage: true })
  await browser.close()
  console.log(`All done, check the screenshot. ✨`)
});

Maybe puppeteer-extra could look for the presence of a browser in the cache and automatically find the installed one ? Probably linked with #728

Edit: Use this answer for better fix: https://github.com/berstend/puppeteer-extra/issues/730#issuecomment-1289776341

vgoklani commented 1 year ago

"win64-1045629"

are you going to update this each time the version changes? :)

I have the same problem too

hamransp commented 1 year ago

Describe the bug

  1. Fresh installation with : npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth
  2. Copy paste the main from puppeteer-extra-plugin-stealth npm
  3. Start the program with node index.js
  4. I get the error Error: An 'executablePath' or 'channel' must be specified for 'puppeteer-core': image

Code Snippet

// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('puppeteer-extra');

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());

// puppeteer usage as normal
puppeteer.launch({ headless: true }).then(async browser => {
  console.log('Running tests..')
  const page = await browser.newPage()
  await page.goto('https://bot.sannysoft.com')
  await page.waitForTimeout(5000)
  await page.screenshot({ path: 'testresult.png', fullPage: true })
  await browser.close()
  console.log(`All done, check the screenshot. ✨`)
});

Versions

  System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
    Memory: 8.58 GB / 15.95 GB
  Binaries:
    Node: 16.13.2 - D:\Program Files\nodejs\node.EXE
    npm: 8.1.2 - D:\Program Files\nodejs\npm.CMD
  npmPackages:
    puppeteer: ^19.1.0 => 19.1.0
    puppeteer-extra: ^3.3.4 => 3.3.4
    puppeteer-extra-plugin-stealth: ^2.11.1 => 2.11.1

=================================== Edit So it seems that puppeteer-core require now the executablePath as mandatory? I think this is new I never got this error before.

I fixed it by adding the path to the chrome.exe file:

const os = require("os");
// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('puppeteer-extra');

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());

// puppeteer usage as normal
puppeteer.launch({ headless: true, executablePath: `${os.homedir()}/.cache/puppeteer/chrome/win64-1045629/chrome-win/chrome.exe`}).then(async browser => {
  console.log('Running tests..')
  const page = await browser.newPage()
  await page.goto('https://bot.sannysoft.com')
  await page.waitForTimeout(5000)
  await page.screenshot({ path: 'testresult.png', fullPage: true })
  await browser.close()
  console.log(`All done, check the screenshot. ✨`)
});

Maybe puppeteer-extra could look for the presence of a browser in the cache and automatically find the installed one ? Probably linked with #728

Same Problem

yerbacode commented 1 year ago

Same here

alextim commented 1 year ago

Same error

bribes commented 1 year ago

Same here

Edit:

Solutions:

C-o-d-e-C-o-w-b-o-y commented 1 year ago

Thanks @bribes, this worked for me:

import { executablePath } from 'puppeteer';
import puppeteer from 'puppeteer-extra';

  const browser = await puppeteer.launch({
    headless: true,
    executablePath: executablePath(),
  });
rothnic commented 1 year ago

Any ideas for how to work around this issue if you can't leverage the full puppeteer in production? See the Sparticuz/chromium project to use headless chrome in a lambda function. None of the mentioned workarounds work for me.

I didn't test using https://www.npmjs.com/package/puppeteer-chromium-resolver, but that seems to download chromium, which is something already handled by the Sparticuz/chromium project.

I did try using executablePath: require('puppeteer').executablePath(), but instead like executablePath: require('puppeteer-core').executablePath(). That results in an error of _projectRoot is undefined. Unable to create a BrowserFetcher.

kanran111 commented 1 year ago

Same here

Edit:

Solutions:

oh man you save my day

MrMegamind commented 8 months ago

For me, I had to:

  1. npm cache clean --force
  2. Delete C:\Users\Administrator.cache\puppeteer
  3. Delete node_modules folder (npm remove puppeteer might also work but did not try)
  4. Run npm install

Everything fixed.

I have no idea what was issue but this helped me finally after going through all above

chouzzy commented 5 months ago

Same here

Edit:

Solutions:

Worked for me, 12h trying to fix this, you helped me a lot, thanks mate :)