Skip to content

Fix Electron renderer process compatability - #22619

Merged
sbc100 merged 4 commits into
emscripten-core:mainfrom
idranme:main
Sep 25, 2024
Merged

Fix Electron renderer process compatability#22619
sbc100 merged 4 commits into
emscripten-core:mainfrom
idranme:main

Conversation

@idranme

@idranme idranme commented Sep 25, 2024

Copy link
Copy Markdown
Contributor

Comment thread src/shell.js
// N.b. Electron.js environment is simultaneously a NODE-environment, but
// also a web environment.
var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string' && process.type != 'renderer';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does electron set process.versions.node? It looks like the check for process.versions.node was added specifically to deal with electron.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does electron set process.versions.node?

Yes
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Was that always the case?

It seems that the processs.versions.node check here was explicitly added to distinguish between node and electron: e9971d1.

In any case it seems like you don't need both the process.versions.node check and the process.type check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://www.electronjs.org/docs/latest/tutorial/electron-timelines
Electron v22.0.0 comes with Node.js as v16.17.
Electron v22.0.0 was released in 2022, while e9971d1 is for 2019.

@idranme idranme Sep 25, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

image

The process comes from the contextBridge.exposeInMainWorld('process', process) in the preload script.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So its possible to expose the process module in some way.. but process.type will always be renderer?

In that case this LGTM, but can you drop the process.versions.node check?

Again I wish we had some kind of testing for electron in our CI :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So its possible to expose the process module in some way.. but process.type will always be renderer?

Yes
image
This is the result under Electron v32

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In that case this LGTM, but can you drop the process.versions.node check?

Feels like it's possible, but not sure it'll work on a version that's too old.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually I think we do still want the process.versions.node check, so that if process is defined by some other means its doesn't trigger this to be true.

@sbc100

sbc100 commented Sep 25, 2024

Copy link
Copy Markdown
Collaborator

Looks like this change replaces #17684

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm.

You can rebaseline the codesize tests using test/runner other.*code_size* other.*codesize* --rebaseline

@idranme

idranme commented Sep 25, 2024

Copy link
Copy Markdown
Contributor Author

You can rebaseline the codesize tests using test/runner other.*code_size* other.*codesize* --rebaseline

OK

@sbc100 sbc100 changed the title Compatible with Elecrton renderer process Fix Electron renderer process compatability Sep 25, 2024
@sbc100

sbc100 commented Sep 25, 2024

Copy link
Copy Markdown
Collaborator

Oh, I forget to say, its best to do emsdk install tot whevever do rebaseline any codesize expectations.

@yosoymin

Copy link
Copy Markdown

Hi, I don't really understand the purpose of this PR, but at the moment, this little change && process.type != 'renderer' makes impossible to use NODEFS inside Electron with nodeIntegration. Is there another approach to fix whatever this PR solves?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants