Skip to content

Commit aec8c25

Browse files
committed
fix: clear sender on native host destroyed
1 parent 9b52002 commit aec8c25

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/electron-chrome-extensions/src/browser/api/lib/native-messaging-host.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async function readNativeMessagingHostConfig(
9999
}
100100
export class NativeMessagingHost {
101101
private process?: ReturnType<typeof spawn>
102-
private sender: ExtensionSender
102+
private sender?: ExtensionSender
103103
private connectionId: string
104104
private connected: boolean = false
105105
private pending?: any[]
@@ -130,10 +130,11 @@ export class NativeMessagingHost {
130130
this.process.kill()
131131
this.process = undefined
132132
}
133-
if (this.keepAlive) {
133+
if (this.keepAlive && this.sender) {
134134
this.sender.ipc.off(`crx-native-msg-${this.connectionId}`, this.receiveExtensionMessage)
135135
this.sender.send(`crx-native-msg-${this.connectionId}-disconnect`)
136136
}
137+
this.sender = undefined
137138
}
138139

139140
private async launch(application: string, extensionId: string) {
@@ -216,7 +217,7 @@ export class NativeMessagingHost {
216217
const length = data.readUInt32LE(0)
217218
const message = JSON.parse(data.subarray(4, 4 + length).toString())
218219
d('receive: %s', message)
219-
if (this.keepAlive) {
220+
if (this.keepAlive && this.sender) {
220221
this.sender.send(`crx-native-msg-${this.connectionId}`, message)
221222
} else {
222223
this.resolveResponse?.(message)

0 commit comments

Comments
 (0)