Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can't use puppeteer-core anymore due to error _projectRoot is undefined. Unable to create a BrowserFetcher #8919

Closed
christian-bromann opened this issue Sep 8, 2022 · 7 comments · Fixed by #8920 or #8921

Comments

@christian-bromann
Copy link
Contributor

christian-bromann commented Sep 8, 2022

Bug description

I am using Puppeteer within WebdriverIO to run commands through DevTools. Unfortunately it is not possible anymore to use puppeteer-core only as utility to launch browser (chrome and firefox). However the docs clearly suggest that this is still possible:

When using puppeteer-core, remember to change the include line:

const puppeteer = require('puppeteer-core');

You will then need to call puppeteer.connect or puppeteer.launch with an explicit executablePath or channel option.

Steps to reproduce the problem:

  1. Create a new folder, e.g. cd /tmp && mkdir pptrtest && cd pptrtest
  2. Install puppeteer-core via npm i puppeteer-core
  3. Create the following script:
const puppeteer = require('puppeteer-core');

(async () => {
    const pathToExtension = require('path').join(__dirname, 'my-extension');
    const browser = await puppeteer.launch({
        product: 'firefox',
        executablePath: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin',
        headless: true,
        defaultViewport: {
            width: 1200,
            height: 900
        }
    });
    await page.goto('https://webdriver.io');
    console.log(await page.title());
    // Test the background page as you would any other page.
    await browser.close();
})();
  1. Run via node test.js

Puppeteer version

latest

Node.js version

18.6.0

npm version

8.5.5

What operating system are you seeing the problem on?

macOS

Relevant log output

/private/tmp/pptrcore/node_modules/puppeteer-core/lib/cjs/puppeteer/node/FirefoxLauncher.js:125
                throw new Error('_projectRoot is undefined. Unable to create a BrowserFetcher.');
                      ^

Error: _projectRoot is undefined. Unable to create a BrowserFetcher.
    at FirefoxLauncher._updateRevision (/private/tmp/pptrcore/node_modules/puppeteer-core/lib/cjs/puppeteer/node/FirefoxLauncher.js:125:23)
    at FirefoxLauncher.launch (/private/tmp/pptrcore/node_modules/puppeteer-core/lib/cjs/puppeteer/node/FirefoxLauncher.js:70:20)
    at async /private/tmp/pptrcore/test.js:5:21
@christian-bromann
Copy link
Contributor Author

christian-bromann commented Sep 8, 2022

The bug got recently introduced with #8907

christian-bromann added a commit to webdriverio/webdriverio that referenced this issue Sep 8, 2022
@OrKoN OrKoN added the confirmed label Sep 8, 2022
OrKoN added a commit that referenced this issue Sep 8, 2022
…8920)

* fix: FirefoxLauncher should not use BrowserFetcher in puppeteer-core

Closes #8919

Co-authored-by: Thiago Perrotta <tbperrotta@gmail.com>
@christian-bromann
Copy link
Contributor Author

Thanks for the quick fix!

@clarkmcc
Copy link

I'm still seeing this issue when running on fly.io.

2022-09-13T21:40:07.751 app[ad36132e] sea [info] Browser creation: Error: _projectRoot is undefined. Unable to create a BrowserFetcher.
2022-09-13T21:40:07.751 app[ad36132e] sea [info] at resolveExecutablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:128:15)
2022-09-13T21:40:07.751 app[ad36132e] sea [info] at ChromeLauncher.launch (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:68:100)
2022-09-13T21:40:07.751 app[ad36132e] sea [info] at async logIn (/workspace/ivie.js:11:19)
2022-09-13T21:40:07.751 app[ad36132e] sea [info] at async /workspace/index.js:216:28

Here's the Dockerfile

FROM node:slim
RUN apt-get update \
  && apt-get install curl gnupg -y \
  && curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
  && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
  && apt-get update \
  && apt-get install google-chrome-stable -y --no-install-recommends \
  && apt-get remove google-chrome-stable -y \
COPY *.json ./
RUN npm install --frozen-lockfile
COPY . ./
CMD node index.js

And launching puppeteer

const browser = await puppeteer.launch({
	headless: true,
	args: [
		// Required for Docker version of Puppeteer
		'--no-sandbox',
		'--disable-setuid-sandbox',
		// This will write shared memory files into /tmp instead of /dev/shm,
		// because Docker’s default for /dev/shm is 64MB
		'--disable-dev-shm-usage',
	]
});

And package.json version

"puppeteer-core": "^17.1.3"

@clarkmcc
Copy link

@clarkmcc I believe you are missing the executablePath or channel when using puppeteer-core: You will then need to call [puppeteer.connect](https://pptr.dev/api/puppeteer.puppeteer.connect) or [puppeteer.launch](https://pptr.dev/api/puppeteer.puppeteernode.launch) with an explicit executablePath or channel option.

Same issue with the env variable

const browser = await puppeteer.launch({
	executablePath: process.env.PUPPETEER_EXECUTABLE_PATH,
	headless: true,
	args: [
		// Required for Docker version of Puppeteer
		'--no-sandbox',
		'--disable-setuid-sandbox',
		// This will write shared memory files into /tmp instead of /dev/shm,
		// because Docker’s default for /dev/shm is 64MB
		'--disable-dev-shm-usage',
	]
});

@OrKoN
Copy link
Collaborator

OrKoN commented Sep 14, 2022

@clarkmcc what is the value of PUPPETEER_EXECUTABLE_PATH that you set?

@clarkmcc
Copy link

@OrKoN, apparently it's undefined. I thought it was provided by the Docker image I was using. Sorry for the false alarm, I'll keep noodling on the env variable/Docker image side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants