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

fix: always use ENV executable path when present #7985

Merged
merged 1 commit into from Feb 11, 2022

Conversation

jbielick
Copy link
Contributor

@jbielick jbielick commented Feb 9, 2022

What kind of change does this PR introduce?

Fixes #7981

These changes:

  1. Allow the ENV variable to always be used when defined and not specified in LaunchOptions (and when not puppeteer-core)
  2. Retain the existing behavior of assuming /usr/bin/chromium-browser on platforms like Ubuntu, Alpine (exact if-conditions preserved to avoid any breaking changes + an added check for file.exists?)
  3. Add some tests for this particular portion of the code.

Did you add tests for your changes?

Yes

If relevant, did you update the documentation?

No. I could add a note about precedence if desired.

Summary

#7981

On linux/arm64, puppeteer always assumes /usr/bin/chromium-browser exists. It ignores PUPPETEER_EXECUTABLE_PATH and fails when /usr/bin/chromium-browser doesn't exist. Not all linux distros install to /usr/bin/chromium-browser, so it would be better to allow PUPPETEER_EXECUTABLE_PATHto have precedence. Debian for instance installs to /usr/bin/chromium. I can't launch chromium unless I explicitly pass an executable path inLaunchOptions`.

Some recent changes to allow arm64 environments (including M1 macs) to launch a chromium installation successfully before arm-compatible builds were downloadable prevented the usage of PUPPETEER_EXECUTABLE_PATH in some environments. Currently, when the platform is not darwin and the arch is arm64, an executable cannot be specified using the environment variable.

Generally speaking, environment variables have highest precedence for options such as this since they depend on system configuration.

Does this PR introduce a breaking change?

No. An executablePath provided via LaunchOptions always gets used. If empty, the ENV var is used. The assumed default executable of /usr/bin/chromium-browser is retained in case its being relied on (though, if PUPPETEER_EXECUTABLE_PATH is also set, it would start working differently). The assumed scope of if not darwin and arm64 was too broad, so this narrows it. /usr/bin/chromium-browser would be present if the OS was Ubuntu, but not Debian. I presume Ubuntu is more common so it was used.

@@ -146,15 +146,9 @@ class ChromeLauncher implements ProductLauncher {

chromeExecutable = executablePathForChannel(channel);
} else if (!executablePath) {
// Use Intel x86 builds on Apple M1 until native macOS arm64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed the point, but this comment seems outdated because /usr/bin/chromium-browser isn't always an x86 build and the comment does not match the condition !== 'darwin'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks it was introduced in #7099

const ubuntuChromiumPath = '/usr/bin/chromium-browser';
if (
product === 'chrome' &&
os.platform() !== 'darwin' &&
Copy link
Contributor Author

@jbielick jbielick Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was tempting to change this to os.platform() === 'linux' because /usr/bin/chromium-browser seemed only applicable to Ubuntu from what I could tell APK (alpine) also uses this location.

Copy link
Contributor Author

@jbielick jbielick Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't seem like os.arch() === 'arm64' should be retained anymore. Whether chromium-browser amd64 or arm64 build is installed it will be in the same location. Should it be retained so that it only behaves this way on arm64 systems because that's the way it used to behave? The current conditions here would add preference to a pre-installed /usr/bin/chromium-browser instead of downloading one on non-darwin platforms.

I've updated this to retain the os.arch() === 'arm64' so no breaking change would occur in which a pre-existing chromium installation would take automatic precedence over the normally downloaded chromium.

@jbielick jbielick force-pushed the executable-path-env-precedence branch from e46fa4f to eef8172 Compare February 9, 2022 22:12
@OrKoN OrKoN force-pushed the executable-path-env-precedence branch from eef8172 to e737705 Compare February 10, 2022 07:51
@jbielick jbielick force-pushed the executable-path-env-precedence branch from e737705 to 98844c4 Compare February 10, 2022 13:49
@jbielick
Copy link
Contributor Author

Seeing the firefox test fail leads me to believe a couple of these tests should have itChromeOnly so they only run for chrome since the product === 'chrome is in the conditional for the asserted behavior. Updated pushed.

@OrKoN OrKoN force-pushed the executable-path-env-precedence branch 2 times, most recently from cbe8cdb to ceeebce Compare February 10, 2022 15:48
Some recent changes to allow arm64 environments (including M1 macs) to
launch a chromium installation successfully before arm-compatible builds
were downloadable prevented the usage of PUPPETEER_EXECUTABLE_PATH in
some environments. Currently, when the platform is not darwin and the
arch is arm64, an executable cannot be specified using the environment
variable.

Generally speaking, environment variables have highest precedence for
options such as this since they depend on system configuration.

These change:

1. allow the ENV variable to always be used when defined and not
   specified in LaunchOptions (and when not puppeteer-core)
2. Retain the existing behavior of assuming /usr/bin/chromium-browser on
   platforms like Ubuntu (exact if-conditions preserved to avoid any
   breaking changes)
3. Add some tests for this particular portion of the code.
@OrKoN OrKoN force-pushed the executable-path-env-precedence branch from ceeebce to 599dc96 Compare February 11, 2022 12:27
@OrKoN
Copy link
Collaborator

OrKoN commented Feb 11, 2022

LGTM (requesting a second review from @jrandolf)

Copy link
Contributor

@jrandolf-zz jrandolf-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@OrKoN OrKoN enabled auto-merge (squash) February 11, 2022 12:47
@OrKoN OrKoN disabled auto-merge February 11, 2022 12:48
@OrKoN OrKoN enabled auto-merge (squash) February 11, 2022 12:48
@OrKoN OrKoN merged commit 6d6ea9b into puppeteer:main Feb 11, 2022
@jbielick
Copy link
Contributor Author

Thank you, @OrKoN and @jrandolf

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

Successfully merging this pull request may close these issues.

[Bug]: PUPPETEER_EXECUTABLE_PATH not respected on Linux/aarch64
3 participants