Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
fix: EventEmitter is missing properties in sandbox preload script. (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
marekharanczyk authored and khalwa committed Feb 22, 2023
1 parent dd3533b commit 2a96c35
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions spec/api-browser-window-spec.ts
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions 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);
})();

0 comments on commit 2a96c35

Please sign in to comment.