diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index 306388f340d3..1277e51ff439 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -150,22 +150,21 @@ const removeRemoteListenersAndLogWarning = (meta, args, callIntoRenderer) => { let message = `Attempting to call a function in a renderer window that has been closed or released.` + `\nFunction provided here: ${meta.location}` - if (args.length === 0) return message - if (!args[0].sender || !args[0].sender.eventNames) return message - - const sender = args[0].sender - const remoteEvents = sender.eventNames().filter((eventName) => { - return sender.listeners(eventName).includes(callIntoRenderer) - }) - - if (remoteEvents.length > 0) { - message += `\nRemote event names: ${remoteEvents.join(', ')}` - remoteEvents.forEach((eventName) => { - sender.removeListener(eventName, callIntoRenderer) + if (args.length > 0 && args[0].sender && args[0].sender.eventNames) { + const sender = args[0].sender + const remoteEvents = sender.eventNames().filter((eventName) => { + return sender.listeners(eventName).includes(callIntoRenderer) }) + + if (remoteEvents.length > 0) { + message += `\nRemote event names: ${remoteEvents.join(', ')}` + remoteEvents.forEach((eventName) => { + sender.removeListener(eventName, callIntoRenderer) + }) + } } - return message + console.warn(message) } // Convert array of meta data from renderer into array of real values. @@ -218,7 +217,7 @@ const unwrapArgs = function (sender, args) { if (!sender.isDestroyed() && webContentsId === sender.getId()) { sender.send('ELECTRON_RENDERER_CALLBACK', meta.id, valueToMeta(sender, args)) } else { - console.warn(removeRemoteListenersAndLogWarning(meta, args, callIntoRenderer)) + removeRemoteListenersAndLogWarning(meta, args, callIntoRenderer) } }