Arguments for Chromium in an Electron.NET app
I am running Windows 10 on an iMac with screen scaling. Chromium has issues with that scaling which results in low FPS (around 15). I also see this low FPS when I run my Electron.NET app. When I start chromium with the arguments "--high-dpi-support=1" and "--force-device-scale-factor=1" it runs much better.
How can I enable these chromium arguments in my Electron.NET app?
This stackoverflow question might give you some way to do this.
https://stackoverflow.com/questions/57900207/how-to-avoid-windows-zoom-in-electron-app
Basically it's recommending that you append the switches to the command arguments in the main process. I imagine you could do this inside the host hook as well.
Hi @danatcofo
Thanks for your reply!
Acctualy, I tried to set these switches via:
Electron.App.CommandLine.AppendSwitch("high-dpi-support", "1");
Electron.App.CommandLine.AppendSwitch("force-device-scale-factor", "1");
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
new BrowserWindowOptions
{
Width = 1152,
Height = 940,
Show = false,
WebPreferences = new WebPreferences
{
Webgl = true,
AllowRunningInsecureContent = true,
WebSecurity = false
}
}
);
await browserWindow.WebContents.Session.ClearCacheAsync();
// For the gracefull showing of the Electron Window when ready
browserWindow.OnReadyToShow += () =>
{
browserWindow.Show();
browserWindow.Maximize();
};
browserWindow.OnReadyToShow += () => browserWindow.Show();
but this has unfortunatelly no effect.
Does anyone an idea how to pass these arguments to Chromium in Electron.NET?
Do it in the host hook js, I believe the .net properties are read only their and won't affect electron.
Remember this is a combo of electron & .net, sometimes you need to get down to the electron.
I created a ElectronHostHook using the electronize add hosthook command. This has created an ElectronHostHook folder with an index.js and a package.json file in it. The index.js looks like this:
// @ts-ignore
import * as Electron from "electron";
import { Connector } from "./connector";
export class HookService extends Connector {
constructor(socket: SocketIO.Socket, public app: Electron.App) {
super(socket, app);
}
onHostReady(): void {
// execute your own JavaScript Host logic here
}
}
but I don't know where to add the
app.commandLine.appendSwitch("high-dpi-support", "1");
app.commandLine.appendSwitch("force-device-scale-factor", "1");
lines. Any hint?
https://www.electronjs.org/docs/latest/api/app
const { app } = require('electron');
Or something similar
Or in your case given the snippet posted
Const app = Electron.app
This is how my index.ts in the ElectronHostHook folder now looks like:
// @ts-ignore
import * as Electron from "electron";
import { Connector } from "./connector";
export class HookService extends Connector {
constructor(socket: SocketIO.Socket, public app: Electron.App) {
super(socket, app);
}
onHostReady(): void {
// execute your own JavaScript Host logic here
const app = Electron.app;
app.commandLine.appendSwitch("high-dpi-support", "true");
app.commandLine.appendSwitch("force-device-scale-factor", "1");
console.log("HostHook has been initialized");
}
}
But nothing has changed. Not even the console.log output can be seen in the terminal although I see that the ElectronHostHook is executed:

I think its all about customizing the main.js which for Electron.NET is created automatically from the electron.manifest.json.
I also tried to explicitely specify a main.js with the electron.manifest.json command: "main": "my_main.js", but this is not working as well.
I'm really lost how to solve this issue...
Honestly I'm just googling ideas here.
https://www.geeksforgeeks.org/command-line-arguments-in-electronjs/amp/
You could do the same. But this is an electron issue at its heart. Sorry trying to help.