Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Sep 15, 2022

Conversation

marekharanczyk
Copy link
Contributor

@marekharanczyk marekharanczyk commented Aug 31, 2022

Description of Change

Add EventEmitter to package.json (version is based on webpack 5 requirements).

After update to webpack 5 missing events dependency was causing EventEmitter created in renderer preload script to be missing properties, for example eventNames, getMaxListeners, prependListener, prependOnceListener, etc. Add it so that it can be used properly from electron libs, sandbox renderer init scripts specifically.

Checklist

Release Notes

Notes: Fixed an issue with incomplete EventEmitter object in sandboxed renderer preload script.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Aug 31, 2022
@marekharanczyk
Copy link
Contributor Author

Beside added test here is a gist to test it : https://gist.github.com/eec01457cf39fb999b6e6ce775912476

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please expand the release notes section in the PR description!

@@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does webpack automatically detect this module somehow? I'm surprised that just adding it to package.json is enough to have this be added to the preload bundle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late answer, I was on vacation. I have not looked into webpack internals that much to be honest. Most migration guides state that you should include what you use, so I just did that, similarly to original PR adding process and buffer.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Sep 7, 2022
@@ -2970,6 +2970,26 @@ describe('BrowserWindow module', () => {
expect(url).to.equal(expectedUrl);
});

it('exposes full EventEmmiter object to preload script', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('exposes full EventEmmiter object to preload script', async () => {
it('exposes full EventEmitter object to preload script', async () => {

Comment on lines 4 to 10
let rendererEventEmitterProperties = '';
let currentObj = emitter;
do {
Object.getOwnPropertyNames(currentObj).map(property => { rendererEventEmitterProperties += property + ';'; });
} while ((currentObj = Object.getPrototypeOf(currentObj)));
const { ipcRenderer } = require('electron');
ipcRenderer.send('answer', rendererEventEmitterProperties);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be an array of strings, no need to flatten it out to a string.

Suggested change
let rendererEventEmitterProperties = '';
let currentObj = emitter;
do {
Object.getOwnPropertyNames(currentObj).map(property => { rendererEventEmitterProperties += property + ';'; });
} while ((currentObj = Object.getPrototypeOf(currentObj)));
const { ipcRenderer } = require('electron');
ipcRenderer.send('answer', rendererEventEmitterProperties);
let rendererEventEmitterProperties = [];
let currentObj = emitter;
do {
rendererEventEmitterProperties.push(...Object.getOwnPropertyNames(currentObj));
} while ((currentObj = Object.getPrototypeOf(currentObj)));
const { ipcRenderer } = require('electron');
ipcRenderer.send('answer', rendererEventEmitterProperties);

@nornagon nornagon added semver/patch backwards-compatible bug fixes no-backport labels Sep 15, 2022
@nornagon nornagon merged commit 532162d into electron:main Sep 15, 2022
@release-clerk
Copy link

release-clerk bot commented Sep 15, 2022

Release Notes Persisted

Fixed an issue with incomplete EventEmitter object in sandboxed renderer preload script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants