Skip to content

Commit

Permalink
fix: check if executablePath exists
Browse files Browse the repository at this point in the history
Closes #12025
  • Loading branch information
OrKoN committed Apr 4, 2024
1 parent 7bc5e0f commit bbc37f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion test/installation/assets/puppeteer-core/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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

0 comments on commit bbc37f0

Please sign in to comment.