How to pass an argument to electron when using electron-builder?
Asked Answered
L

3

14

I'm building an application with Electron and packaging with Electron Builder. When running electron, I want to pass this command line argument: --enable-mixed-sandbox.

Is it possible? How?

This:

 app.commandLine.appendSwitch('enable-mixed-sandbox')

wouldn't work due to:

Note that it is not enough to call app.commandLine.appendSwitch('--enable-sandbox'), as electron/node startup code runs after it is possible to make changes to chromium sandbox settings. The switch must be passed to electron on the command-line:

electron --enable-sandbox app.js

It is not possible to have the OS sandbox active only for some renderers, if --enable-sandbox is enabled, normal electron windows cannot be created.

Landlordism answered 24/7, 2017 at 19:22 Comment(5)
I suppose the easiest way is to edit the shortcut so that it launches with that option. Not sure how to do that programmatically though.Conatus
github.com/electron-userland/electron-builder/issues/1905Conatus
@Conatus those arguments don't reach electron as far as I know. Do you know otherwise?Landlordism
Try it manually and see what happens?Conatus
I've changed my answer substantially.Conatus
D
0

enable-mixed-sandbox is not a valid Electron command line flag. See here for all available command line flags for Electron.

Disgruntle answered 9/3, 2023 at 21:15 Comment(0)
C
-1

I got a response on that issue I raised and linked to in the comments:

app.enableMixedSandbox() // Experimental macOS Windows

See here for documentation.

Conatus answered 3/8, 2017 at 0:30 Comment(0)
S
-1

another way of doing it, you can use spectron to start the app in debug mode. which allows you to pass any arguments you want.

const Application = require('spectron').Application

// Returns a promise that resolves to a Spectron Application once the app has loaded.
// Takes a Ava test. Makes some basic assertions to verify that the app loaded correctly.
function createApp (t) {
  return new Application({
    path: 'path/to/app',
    args: ['-r', '--enable-mixed-sandbox'],
    env: {NODE_ENV: 'test'},
    waitTimeout: 10e3
  })
}

https://github.com/electron/spectron#new-applicationoptions

Steinmetz answered 7/8, 2017 at 7:52 Comment(2)
How does that work with electron builder to distribute apps? I can pass whatever argument I want in dev mode, that's not the issue. The issue is the .exe generated by electron-builder.Landlordism
well I don't think you can pass sandbox for bundled app because of security concerns. as electron mentioned in docs Some bug in V8 engine may allow malicious code to access the renderer preload APIs, effectively granting full access to the system through the remote module. check this link as well might explain a bit more.Steinmetz

© 2022 - 2024 — McMap. All rights reserved.