Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Expose process.env from sandbox renderer #12166
In non sandbox renderer, apps can use process.env as a way to pass data from main process to renderer process.
This PR provides this functionality in sandbox renderer process.
Why not simply make
process.env redirect to the browser process
env? It is not like the renderer will have a different environment. If there are differences, it will probably be internal to chromium and not useful for electron apps.
If you simply copy
process.env from the browser process at renderer initialization (eg
process.env = remote.process.env), the implementation will be much simpler and in practice it will have the same effect.
Another option would be having
process.env as an alias to
remote.process.env, which would allow one to pick changes to the browser process environment (though how useful that would be I can't say for sure)
@tarruda the reason i went with this approach was to bring parity with non sandbox renderer.
There will be cases where main process is changing process.env and reading from renderer will not work.
I'm not in favor of using remote as it is synchronous retrieval and can cause hangs in apps.
Let me know if see any issues with this.
This is how it currently works in non-sandboxed renderers, the
As @MarshallOfSound explained, the environment is not linked. It is inherited when the process is spawned and then becomes independent. Retrieving the browser process environment at startup via remote would have the same practical effect.
We already use synchronous IPC during startup to read the preload script, one more call to retrieve the environment won't have a significant impact. If optimization is a concern, you can modify the RPC that returns the preload script to return
I'd rather simply use
@tarruda @MarshallOfSound i made the change to JS. If i run through a quick-start app, i see process.env getting reflected with this change as expected. Also variables defined in main process can be retrieved in renderer process.
But, the test i added seem to not get just the variable