diff --git a/lib/browser/ipc-main-internal-utils.ts b/lib/browser/ipc-main-internal-utils.ts index 716f268f5d..6f79986749 100644 --- a/lib/browser/ipc-main-internal-utils.ts +++ b/lib/browser/ipc-main-internal-utils.ts @@ -29,9 +29,17 @@ let nextId = 0 export function invokeInWebContents (sender: Electron.WebContentsInternal, command: string, ...args: any[]) { return new Promise((resolve, reject) => { const requestId = ++nextId - ipcMainInternal.once(`${command}_RESPONSE_${requestId}`, ( - _event, error: Electron.SerializedError, result: any - ) => { + const channel = `${command}_RESPONSE_${requestId}` + ipcMainInternal.on(channel, function handler ( + event, error: Electron.SerializedError, result: any + ) { + if (event.sender !== sender) { + console.error(`Reply to ${command} sent by unexpected WebContents (${event.sender.id})`) + return + } + + ipcMainInternal.removeListener(channel, handler) + if (error) { reject(errorUtils.deserialize(error)) } else {