Repository: electron
Issue: Better support for --js-flags and other CLI arguments in a packaged app
Labels: enhancement :sparkles:

### Preflight Checklist

* [x] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project.
* [x] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to.
* [x] I have searched the issue tracker for a feature request that matches the one I want to file, without success.

### Problem Description

Packaged apps need a lower-touch method of leveraging `--js-flags` and other electron CLI options that can only be passed in as arguments currently.

**Specific use case** 
`--max-old-space-size` to increase V8 heap size of the **main process in production**.

**Additional Context**
Our company builds a photo processing application that moves as much analysis out of the renderer process as possible (IPC to main process for all non-renderer work and heavy utilization of node child processes). We can avoid OOMs in the renderer with `app.commandLine.appendSwitch('js-flags', '--max-old-space-size=XXXX');` but that does us no good for the main process that's already running. This creates a perverse incentive to disable sandboxing and force more logic into the renderer process. Similarly `v8.setFlagsFromString` (and the electron [built-in `v8Flags` package.json property](https://github.com/electron/electron/blob/5e7c59469156ba68f2e161a81dda372c5d5ec429/lib/browser/init.ts#L148)) does no good because the isolate has already been created and `--max-old-space-size` is a noop once the isolate has already been created.

### Importance

This is a [very](https://github.com/electron-userland/electron-builder/issues/3550) [common](https://github.com/electron-userland/electron-builder/issues/3781) [userland](https://github.com/electron-userland/electron-builder/issues/1541) [request](https://stackoverflow.com/questions/45288492/how-to-pass-an-argument-to-electron-when-using-electron-builder) that is frequently misunderstood and [dismissed by userland maintainers as technically infeasible](https://github.com/electron-userland/electron-builder/issues/2562#issuecomment-405187285). Furthermore, all of the common requests for how to increase memory limit in electron core [respond with "use --js-flags"](https://github.com/electron/electron/issues/2056) but no mention of how to make this actually work in production.

Additionally, lowering the barrier to experimenting with new flags in packaged apps could reduce the burden of transitioning features [like sandbox](https://github.com/electron/electron/issues/15760).

### Proposed Solution
Electron reads additional flags from a known filename pattern (`electron.opts` perhaps? naming very much open to suggestion) on startup that can be processed before the v8 isolate is created/other initialization occurs that render setting flags from within the main process "too little too late".

While on first blush this seemed potentially insecure to me, if the user can already pass these exact flags to the application, a malicious user with filesystem access could already modify the shortcut/plist to the same effect.

### Relevant Change Locations

Not entirely sure, maybe here?

https://github.com/electron/electron/blob/19314d3cafc5ec1c4b1f1316b3f5d9744f8e9604/shell/browser/javascript_environment.cc#L48-L54

or here?
https://github.com/electron/electron/blob/19314d3cafc5ec1c4b1f1316b3f5d9744f8e9604/shell/app/node_main.cc#L102-L141 

### Alternatives Considered
- Custom compilations of electron with the flags hardcoded (large amount of work and maintenance, only accessible to a small subset of electron population from what I've seen so far)
- Wrapper around the executable to force the use of particular arguments (difficult cross-platform, undocumented behavior on certain platforms, buggy on macOS)

These are the only two current solutions I'm aware of. If there's a way to achieve what I'm looking for that I missed, I'd love to be wrong here :)


### Resourcing

I'm willing to work on this if there's consensus on a solution and someone willing to point me in the right direction. I used to work on Chromium and am familiar enough with the electron architecture to get this far.

### Related Issues

- https://github.com/electron/electron/issues/2056 (confusion around --max-old-space-size and where to pass it)
- https://github.com/electron/electron/issues/15748 (more asking how to pass flags in)
- https://github.com/electron-userland/electron-builder/issues/2562#issuecomment-405187285 (userland says not technically possible)
- https://github.com/electron-userland/electron-builder/issues/3550 (no answers)
- https://github.com/electron-userland/electron-builder/issues/3103 (misunderstood electron architecture)
- https://github.com/electron-userland/electron-builder/issues/3781 (old space related)
- https://github.com/electron-userland/electron-builder/issues/1541 (misunderstood electron architecture and --max-old-space-size)
- https://stackoverflow.com/questions/45288492/how-to-pass-an-argument-to-electron-when-using-electron-builder (author has same question but no answer)