Skip to content

Commit a67335d

Browse files
committed
Handle browser launch error events
Without this, in some cases (e.g. no permissions to run Chrome) the event is unhandled, and the server crashes. It's better to clearly catch and report this.
1 parent fab62ed commit a67335d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/browsers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,16 @@ export { LaunchOptions };
8383

8484
export const launchBrowser = async (url: string, options: LaunchOptions, configPath: string) => {
8585
const launcher = await getLauncher(configPath);
86-
return await promisify(launcher)(url, options);
86+
const browserInstance = await promisify(launcher)(url, options);
87+
88+
browserInstance.process.on('error', (e) => {
89+
// If nothing else is listening for this error, this acts as default
90+
// fallback error handling: log & report & don't crash.
91+
if (browserInstance.process.listenerCount('error') === 1) {
92+
console.log('Browser launch error');
93+
reportError(e);
94+
}
95+
});
96+
97+
return browserInstance;
8798
};

0 commit comments

Comments
 (0)