Skip to content

Commit

Permalink
fix: apply senderFrame details to ipcMain port event (#33780)
Browse files Browse the repository at this point in the history
Co-authored-by: deepak1556 <hop2deep@gmail.com>
  • Loading branch information
trop[bot] and deepak1556 committed Apr 14, 2022
1 parent b76b7ba commit 50fb4e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/browser/api/web-contents.ts
Expand Up @@ -602,6 +602,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);
});
Expand Down
4 changes: 4 additions & 0 deletions spec-main/api-ipc-spec.ts
Expand Up @@ -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);
});
Expand All @@ -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 () => {
Expand All @@ -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);
Expand Down

0 comments on commit 50fb4e2

Please sign in to comment.