Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/proxyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#endif

#if ENVIRONMENT_MAY_BE_NODE
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';
if (ENVIRONMENT_IS_NODE) {
var NodeWorker = require('worker_threads').Worker;
global.Worker = function(url, options) {
Expand Down
2 changes: 1 addition & 1 deletion src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var ENVIRONMENT_IS_WEB = typeof window == 'object';
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
// 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
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
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
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
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.

Copy link
Contributor Author

@idranme idranme Sep 25, 2024

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
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
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
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
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.

#if AUDIO_WORKLET
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER && !ENVIRONMENT_IS_AUDIO_WORKLET;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var readyPromise = new Promise((resolve, reject) => {
#endif

#if ENVIRONMENT_MAY_BE_NODE
var ENVIRONMENT_IS_NODE = typeof process == 'object';
var ENVIRONMENT_IS_NODE = typeof process == 'object' && process.type != 'renderer';
#endif

#if ENVIRONMENT_MAY_BE_SHELL
Expand Down
2 changes: 1 addition & 1 deletion src/wasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#if ENVIRONMENT_MAY_BE_NODE
// Node.js support
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';
if (ENVIRONMENT_IS_NODE) {
// Create as web-worker-like an environment as we can.

Expand Down