如何在Electron中设置铬命令行标志



我正在开发一个Electron应用程序,需要启用以下Chromium标志GuestViewCrossProcessFrames才能使用webview进行缩放。

我试着在main.js中调用以下行,但似乎不起作用。还尝试为BrowserWindow和webview启用插件。

app.commandLine.appendSwitch('--enable-features=GuestViewCrossProcessFrames');

有人能帮我树立这面旗帜吗?非常感谢。

您可以通过调用进行设置

const { app } = require('electron');
app.commandLine.appendSwitch('enable-features', 'GuestViewCrossProcessFrames');
app.on('ready', () => {
// place your code.
}

注意:您需要在就绪事件发出之前调用它。

我不清楚为什么Electron会这样做,尽管您指定的特定标志在电子中被明确禁用

https://github.com/electron/electron/blob/bcbcb4c6436e84e7f1f2387c2d7581bbdadb5732/brightray/browser/browser_main_parts.cc#L185-L187

因此,您无法动态启用它。

根据文档,调用appendSwitch的正确方式是:

app.commandLine.appendSwitch(switch[, value])

正如OJ Kwon的回答中所提到的,显然enable-features被Electron明确禁用。如果这不是真的,你可以用以下语法设置它:

app.commandLine.appendSwitch('enable-features', 'GuestViewCrossProcessFrames');

有关更多示例,请参阅支持的Chrome命令行开关。

要使用app.commandLine.appendSwitch,请确保不要使用"--",您的呼叫应该像这个

app.commandLine.appendSwitch('enable-features=GuestViewCrossProcessFrames');

最新更新