Skip to content

Commit 3a610f6

Browse files
committed
Fix error when intercepting a non-startable Electron app
1 parent ec9c4a7 commit 3a610f6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/interceptors/electron.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class ElectronInterceptor implements Interceptor {
5454
? await findExecutableInApp(pathToApplication)
5555
: pathToApplication;
5656

57-
spawn(cmd, [`--inspect-brk=${debugPort}`], {
57+
const appProcess = spawn(cmd, [`--inspect-brk=${debugPort}`], {
5858
stdio: 'inherit',
5959
env: Object.assign({},
6060
process.env,
@@ -64,6 +64,21 @@ export class ElectronInterceptor implements Interceptor {
6464

6565
let debugClient: ChromeRemoteInterface.CdpClient | undefined;
6666
let retries = 10;
67+
68+
appProcess.on('error', async (e) => {
69+
reportError(e);
70+
71+
if (debugClient) {
72+
// Try to close the debug connection if open, but very carefully
73+
try {
74+
await debugClient.close();
75+
} catch (e) { }
76+
}
77+
78+
// If we're still in the process of debugging the app, give up.
79+
retries = -1;
80+
});
81+
6782
while (!debugClient && retries >= 0) {
6883
try {
6984
debugClient = await ChromeRemoteInterface({ port: debugPort });

0 commit comments

Comments
 (0)