fix: apply senderFrame details to ipcMain port event (#33756)
This commit is contained in:
parent
3d4d39d67b
commit
16f8d713ab
2 changed files with 5 additions and 0 deletions
|
@ -627,6 +627,7 @@ WebContents.prototype._init = function () {
|
|||
});
|
||||
|
||||
this.on('-ipc-ports' as any, function (event: Electron.IpcMainEvent, internal: boolean, channel: string, message: any, ports: any[]) {
|
||||
addSenderFrameToEvent(event);
|
||||
event.ports = ports.map(p => new MessagePortMain(p));
|
||||
ipcMain.emit(channel, event, message);
|
||||
});
|
||||
|
|
|
@ -212,6 +212,8 @@ describe('ipc module', () => {
|
|||
const [ev, msg] = await p;
|
||||
expect(msg).to.equal('hi');
|
||||
expect(ev.ports).to.have.length(1);
|
||||
expect(ev.senderFrame.parent).to.be.null();
|
||||
expect(ev.senderFrame.routingId).to.equal(w.webContents.mainFrame.routingId);
|
||||
const [port] = ev.ports;
|
||||
expect(port).to.be.an.instanceOf(EventEmitter);
|
||||
});
|
||||
|
@ -226,6 +228,7 @@ describe('ipc module', () => {
|
|||
const [ev, msg] = await p;
|
||||
expect(msg).to.equal('hi');
|
||||
expect(ev.ports).to.deep.equal([]);
|
||||
expect(ev.senderFrame.routingId).to.equal(w.webContents.mainFrame.routingId);
|
||||
});
|
||||
|
||||
it('can communicate between main and renderer', async () => {
|
||||
|
@ -241,6 +244,7 @@ describe('ipc module', () => {
|
|||
}})()`);
|
||||
const [ev] = await p;
|
||||
expect(ev.ports).to.have.length(1);
|
||||
expect(ev.senderFrame.routingId).to.equal(w.webContents.mainFrame.routingId);
|
||||
const [port] = ev.ports;
|
||||
port.start();
|
||||
port.postMessage(42);
|
||||
|
|
Loading…
Reference in a new issue