fix: check if executablePath exists (#12201)

This commit is contained in:
Alex Rudenko 2024-04-04 12:46:35 +02:00 committed by GitHub
parent 7bc5e0fb2d
commit 4ec0280080
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 2 deletions

View File

@ -98,6 +98,12 @@ export abstract class ProductLauncher {
const launchArgs = await this.computeLaunchArguments(options); 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 usePipe = launchArgs.args.includes('--remote-debugging-pipe');
const onProcessExit = async () => { const onProcessExit = async () => {

View File

@ -13,7 +13,11 @@ import puppeteer from 'puppeteer-core';
executablePath: 'node', executablePath: 'node',
}); });
} catch (error) { } 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); process.exit(0);
} }
console.error(error); console.error(error);

View File

@ -190,7 +190,9 @@ describe('Launcher specs', function () {
}).catch(error => { }).catch(error => {
return (waitError = 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 () => { it('userDataDir option', async () => {
const userDataDir = await mkdtemp(TMP_FOLDER); const userDataDir = await mkdtemp(TMP_FOLDER);
@ -615,6 +617,20 @@ describe('Launcher specs', function () {
}); });
expect(error.message).toContain('either pipe or debugging port'); 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 () { describe('Puppeteer.launch', function () {