From 532162d2b5b0e05c1bca3d08e30c4e2b9387ac04 Mon Sep 17 00:00:00 2001 From: marekharanczyk <48673767+marekharanczyk@users.noreply.github.com> Date: Thu, 15 Sep 2022 18:33:08 +0200 Subject: [PATCH] fix: EventEmitter is missing properties in sandbox preload script. (#35522) --- package.json | 1 + spec/api-browser-window-spec.ts | 20 ++++++++++++++++++++ spec/fixtures/module/preload-eventemitter.js | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 spec/fixtures/module/preload-eventemitter.js diff --git a/package.json b/package.json index cbeee0af1e81..aedaa5ba0ebd 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-standard": "^4.0.1", "eslint-plugin-typescript": "^0.14.0", + "events": "^3.2.0", "express": "^4.16.4", "folder-hash": "^2.1.1", "fs-extra": "^9.0.1", diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index a925e6bf066d..de2330b92326 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -2970,6 +2970,26 @@ describe('BrowserWindow module', () => { expect(url).to.equal(expectedUrl); }); + it('exposes full EventEmitter object to preload script', async () => { + const w = new BrowserWindow({ + show: false, + webPreferences: { + sandbox: true, + preload: path.join(fixtures, 'module', 'preload-eventemitter.js') + } + }); + w.loadURL('about:blank'); + const [, rendererEventEmitterProperties] = await emittedOnce(ipcMain, 'answer'); + const { EventEmitter } = require('events'); + const emitter = new EventEmitter(); + const browserEventEmitterProperties = []; + let currentObj = emitter; + do { + browserEventEmitterProperties.push(...Object.getOwnPropertyNames(currentObj)); + } while ((currentObj = Object.getPrototypeOf(currentObj))); + expect(rendererEventEmitterProperties).to.deep.equal(browserEventEmitterProperties); + }); + it('should open windows in same domain with cross-scripting enabled', async () => { const w = new BrowserWindow({ show: true, diff --git a/spec/fixtures/module/preload-eventemitter.js b/spec/fixtures/module/preload-eventemitter.js new file mode 100644 index 000000000000..26b5760de0a4 --- /dev/null +++ b/spec/fixtures/module/preload-eventemitter.js @@ -0,0 +1,11 @@ +(function () { + const { EventEmitter } = require('events'); + const emitter = new EventEmitter(); + const rendererEventEmitterProperties = []; + let currentObj = emitter; + do { + rendererEventEmitterProperties.push(...Object.getOwnPropertyNames(currentObj)); + } while ((currentObj = Object.getPrototypeOf(currentObj))); + const { ipcRenderer } = require('electron'); + ipcRenderer.send('answer', rendererEventEmitterProperties); +})();