Skip to content

Commit b38a070

Browse files
committed
Fix Electron interception issue
On some systems, with the new Node, CDP connections default to ::1 instead of 127.0.0.1, and it seems the Electron debug port is only accessible on 127.0.0.1 by default, so this doesn't work. We now fix both the listening address & target address explicitly, which should ensure these reliably match up correctly in future.
1 parent 39ee81b commit b38a070

File tree

4 files changed

+37
-52
lines changed

4 files changed

+37
-52
lines changed

custom-typings/chrome-remote-interface.d.ts

-46
This file was deleted.

package-lock.json

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@oclif/plugin-update": "^1.3.8",
3838
"@sentry/integrations": "^5.29.2",
3939
"@sentry/node": "^5.29.2",
40+
"@types/chrome-remote-interface": "^0.31.10",
4041
"@types/cors": "^2.8.7",
4142
"@types/dns2": "^2.0.0",
4243
"@types/dockerode": "^3.3.0",

src/interceptors/electron.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class ElectronInterceptor implements Interceptor {
3434
readonly version = '1.0.1';
3535

3636
private debugClients: {
37-
[port: string]: Array<ChromeRemoteInterface.CdpClient>
37+
[port: string]: Array<ChromeRemoteInterface.Client>
3838
} = {};
3939

4040
constructor(private config: HtkConfig) { }
@@ -65,7 +65,7 @@ export class ElectronInterceptor implements Interceptor {
6565
// Non-darwin, or darwin with a full path to the binary:
6666
: pathToApplication;
6767

68-
const appProcess = spawn(cmd, [`--inspect-brk=${debugPort}`], {
68+
const appProcess = spawn(cmd, [`--inspect-brk=127.0.0.1:${debugPort}`], {
6969
stdio: 'inherit',
7070
env: {
7171
...process.env,
@@ -78,7 +78,7 @@ export class ElectronInterceptor implements Interceptor {
7878
}
7979
});
8080

81-
let debugClient: ChromeRemoteInterface.CdpClient | undefined;
81+
let debugClient: ChromeRemoteInterface.Client | undefined;
8282
let retries = 10;
8383

8484
appProcess.on('error', async (e) => {
@@ -97,7 +97,10 @@ export class ElectronInterceptor implements Interceptor {
9797

9898
while (!debugClient && retries >= 0) {
9999
try {
100-
debugClient = await ChromeRemoteInterface({ port: debugPort });
100+
debugClient = await ChromeRemoteInterface({
101+
host: '127.0.0.1',
102+
port: debugPort
103+
});
101104
} catch (error) {
102105
if ((isErrorLike(error) && error.code !== 'ECONNREFUSED') || retries === 0) {
103106
throw error;
@@ -111,7 +114,7 @@ export class ElectronInterceptor implements Interceptor {
111114

112115
this.debugClients[proxyPort] = this.debugClients[proxyPort] || [];
113116
this.debugClients[proxyPort].push(debugClient);
114-
debugClient.once('disconnect', () => {
117+
debugClient.on('disconnect', () => {
115118
_.remove(this.debugClients[proxyPort], c => c === debugClient);
116119
});
117120

@@ -170,7 +173,7 @@ export class ElectronInterceptor implements Interceptor {
170173
this.debugClients[proxyPort].map(async (debugClient) => {
171174
let shutdown = false;
172175
const disconnectPromise = new Promise<void>((resolve) =>
173-
debugClient.once('disconnect', resolve)
176+
debugClient.on('disconnect', resolve)
174177
).then(() => {
175178
shutdown = true
176179
});

0 commit comments

Comments
 (0)