0

As per the documentation https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteer-vs-puppeteer-core, I am trying to use puppeteer-core library instead of puppeteer so that I can install headless-shell instead of default chromium lib that comes with puppeteer.

I download the content-shell.zip for mac from this location https://chromium.cypress.io/mac/canary/89.0.4342.2 and used the below code,

const browser = await puppeteer.launch({executablePath: 'content-shell' });

it fails with the below error, Error: Failed to launch the browser process! spawn content-shell ENOENT

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

at onClose (/Users/ln/mine/sandbox/puppeteer-test/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
at ChildProcess.<anonymous> (/Users/ln/mine/sandbox/puppeteer-test/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:185:85)
at ChildProcess.emit (events.js:315:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
at onErrorNT (internal/child_process.js:465:16)

where to get the headless-shell of chrome for mac, windows and linux versions?

Lokn
  • 421
  • 4
  • 17

3 Answers3

0

There is no separate binary/executable that runs chrome in headless. However, if you are running chrome version 59 or more in Mac and Linux and 60 or more for Windows, which is very likely (seeing the latest version is around 90), using the following should launch chrome in a headless state:

const browser = await puppeteer.launch({
    executablePath: '/path/to/chrome/executable', 
    args: ['--headless']
});

The executable for Mac can generally be found in the application's Contents/MacOS folder:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

For Linux, this might change basis the distribution. However, this might help find it.

Similarly, for Windows, the location changes with the version but this should help in finding it.

Kunal Kukreja
  • 737
  • 4
  • 18
0

According to docs, you have to build it yourself. Download Source Code.

... first initialize a headless build configuration:

$ mkdir -p out/Debug
$ echo 'import("//build/args/headless.gn")' > out/Debug/args.gn
$ gn gen out/Debug

Then build the example:

$ ninja -C out/Debug headless_example

After the build completes, the example can be run with the following command:

$ out/Debug/headless_example https://www.google.com
Faizan AlHassan
  • 389
  • 4
  • 8
0

Looking at the Puppeteer API for the launchOptions object here is what it says for the executablePath property :

type: string

description: (Optional) Path to a browser executable to use instead of the bundled Chromium. Note that Puppeteer is only guaranteed to work with the bundled Chromium, so use this setting at your own risk.

So if defined it should always be a path to a browser executable.
That's why you get this error as 'content-shell' is not a valid path to a browser executable.

Note that the above description is in case of use with puppeteer.
Using puppeteer-core optional goes to required and the following note can be ignored.

Darkosphere
  • 107
  • 8