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: check if executablePath exists #12201

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/puppeteer-core/src/node/ProductLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export abstract class ProductLauncher {

const launchArgs = await this.computeLaunchArguments(options);

if (!existsSync(launchArgs.executablePath)) {
throw new Error(
`Browser was not found at the configured executablePath (${launchArgs.executablePath})`
);
}

const usePipe = launchArgs.args.includes('--remote-debugging-pipe');

const onProcessExit = async () => {
Expand Down
6 changes: 5 additions & 1 deletion test/installation/assets/puppeteer-core/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import puppeteer from 'puppeteer-core';
executablePath: 'node',
});
} catch (error) {
if (error.message.includes('Failed to launch the browser process')) {
if (
error.message.includes(
'Browser was not found at the configured executablePath (node)'
)
) {
process.exit(0);
}
console.error(error);
Expand Down
18 changes: 17 additions & 1 deletion test/src/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ describe('Launcher specs', function () {
}).catch(error => {
return (waitError = error);
});
expect(waitError.message).toContain('Failed to launch');
expect(waitError.message).toBe(
'Browser was not found at the configured executablePath (random-invalid-path)'
);
});
it('userDataDir option', async () => {
const userDataDir = await mkdtemp(TMP_FOLDER);
Expand Down Expand Up @@ -615,6 +617,20 @@ describe('Launcher specs', function () {
});
expect(error.message).toContain('either pipe or debugging port');
});

it('throws an error if executable path is not valid with pipe=true', async () => {
const options = {
executablePath: '/tmp/does-not-exist',
pipe: true,
};
let error!: Error;
await launch(options).catch(error_ => {
return (error = error_);
});
expect(error.message).toContain(
'Browser was not found at the configured executablePath (/tmp/does-not-exist)'
);
});
});

describe('Puppeteer.launch', function () {
Expand Down