diff --git a/lib/browser/api/ipc-main.js b/lib/browser/api/ipc-main.js index 2e45b391f7e8..0c2592f94129 100644 --- a/lib/browser/api/ipc-main.js +++ b/lib/browser/api/ipc-main.js @@ -2,5 +2,13 @@ const EventEmitter = require('events').EventEmitter module.exports = new EventEmitter() +const removeAllListeners = module.exports.removeAllListeners +module.exports.removeAllListeners = function (...args) { + if (args.length === 0) { + throw new Error('Removing all listeners from ipcMain will make Electron internals stop working. Please specify a event name') + } + removeAllListeners.apply(this, args) +} + // Do not throw exception when channel name is "error". module.exports.on('error', () => {}) diff --git a/lib/renderer/api/ipc-renderer-setup.js b/lib/renderer/api/ipc-renderer-setup.js index 76fdbb5f0e52..2cebc6a9c3ee 100644 --- a/lib/renderer/api/ipc-renderer-setup.js +++ b/lib/renderer/api/ipc-renderer-setup.js @@ -29,4 +29,12 @@ module.exports = function (ipcRenderer, binding) { ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', true, webContentsId, channel, ...args) } + + const removeAllListeners = ipcRenderer.removeAllListeners + ipcRenderer.removeAllListeners = function (...args) { + if (args.length === 0) { + throw new Error('Removing all listeners from ipcRenderer will make Electron internals stop working. Please specify a event name') + } + removeAllListeners.apply(this, args) + } }