Browse Source

feat: warn when ipcRenderer.sendSync() called with no listeners for channel (#31433)

Co-authored-by: Milan Burda <[email protected]>
trop[bot] 3 years ago
parent
commit
76e9225c2b
1 changed files with 3 additions and 0 deletions
  1. 3 0
      lib/browser/api/web-contents.ts

+ 3 - 0
lib/browser/api/web-contents.ts

@@ -593,6 +593,9 @@ WebContents.prototype._init = function () {
       ipcMainInternal.emit(channel, event, ...args);
     } else {
       addReplyToEvent(event);
+      if (this.listenerCount('ipc-message-sync') === 0 && ipcMain.listenerCount(channel) === 0) {
+        console.warn(`WebContents #${this.id} called ipcRenderer.sendSync() with '${channel}' channel without listeners.`);
+      }
       this.emit('ipc-message-sync', event, channel, ...args);
       ipcMain.emit(channel, event, ...args);
     }