fix: EventEmitter is missing properties in sandbox preload script. (#35522)

This commit is contained in:
marekharanczyk 2022-09-15 18:33:08 +02:00 committed by GitHub
parent 30bdede09f
commit 532162d2b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View file

@ -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",

View file

@ -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,

View file

@ -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);
})();