fix: throw instead of crash when using ipcRenderer after context released (#23917)
This commit is contained in:
parent
491caf59c1
commit
a1c55a13e1
2 changed files with 55 additions and 1 deletions
|
@ -9,7 +9,7 @@ describe('ipcRenderer module', () => {
|
|||
|
||||
let w: BrowserWindow;
|
||||
before(async () => {
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nativeWindowOpen: true } });
|
||||
await w.loadURL('about:blank');
|
||||
});
|
||||
after(async () => {
|
||||
|
@ -182,4 +182,25 @@ describe('ipcRenderer module', () => {
|
|||
expect(result).to.deep.equal([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('after context is released', () => {
|
||||
it('throws an exception', async () => {
|
||||
const error = await w.webContents.executeJavaScript(`(${() => {
|
||||
const child = window.open('', 'child', 'show=no,nodeIntegration=yes')! as any;
|
||||
const childIpc = child.require('electron').ipcRenderer;
|
||||
child.close();
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
childIpc.send('hello');
|
||||
} catch (e) {
|
||||
resolve(e);
|
||||
}
|
||||
resolve(false);
|
||||
}, 100);
|
||||
});
|
||||
}})()`);
|
||||
expect(error).to.have.property('message', 'IPC method called after context was released');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue