fix: apply senderFrame details to ipcMain port event (#33756)

This commit is contained in:
Robo 2022-04-14 13:01:00 +09:00 committed by GitHub
parent 3d4d39d67b
commit 16f8d713ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View file

@ -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);
});

View file

@ -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);