13

我正在使用 Electron 构建应用程序并使用 Electron Builder 进行打包。运行电子时,我想传递这个命令行参数: --enable-mixed-sandbox

可能吗?如何?

这个:

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

由于以下原因无法工作:

请注意,调用 app.commandLine.appendSwitch('--enable-sandbox') 是不够的,因为电子/节点启动代码在可以更改铬沙箱设置之后运行。开关必须在命令行上传递给电子:

electron --enable-sandbox app.js

无法仅对某些渲染器启用 OS 沙箱,如果启用了 --enable-sandbox,则无法创建正常的电子窗口。

4

3 回答 3

0

您可以app.commandLine.appendSwitch在您的应用程序主脚本中使用(打开电子窗口的那个)

你的开关的例子是

    app.commandLine.appendSwitch('启用混合沙盒')

于 2017-07-25T23:08:00.270 回答
-1

我收到了关于我在评论中提出并链接到的那个问题的回复:

app.enableMixedSandbox() // Experimental macOS Windows

有关文档,请参见此处

于 2017-08-03T00:30:19.863 回答
-1

另一种方法是,您可以使用 spectron 在调试模式下启动应用程序。它允许你传递你想要的任何参数。

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

于 2017-08-07T07:52:10.750 回答