Access env variable or cli argument from client extension

It seems like we can access custom cli options with this feature: https://github.com/eclipse-theia/theia/commit/4ad0999a18ff496cffb823a06b64da233dd3e027. However I wasn’t able to find an example and the things I tried didn’t work. What I’m trying to do: I have a browser extension and I need to access either an env variable or cli option passed from the yarn theia start command. It seems like this is possible with both env variables and cli args, but I’m struggling to figure out how to do this from within my extension.

[original thread by Ben Sidelinger]

To access env variable: process.MY_ENV_VARIABLE

in the referenced PR there is BackendApplicationCliContribution look how it is bound and used for cli arguments

[Ben Sidelinger]

Hey @anton-kosyakov so I can access a “process” global (not sure exactly how this magic happens, since window.process doesn’t seem to be defined) in my extension, but it’s just this: {“title”:“browser”,“browser”:true,“env”:{},“argv”:[],“version”:"",“versions”:{}}. I tried running theia start like so: THEME=bright yarn theia start, but it didn’t work to populate process.env as it would on the server. Is your answer specifically to access env variables passed to theia start?

You can access it only on the backend

You cannot use cli contribution or process node.js api in the browser.

[Ben Sidelinger]

I see, thanks @anton-kosyakov I guess I’ll go another route.