Arguments for Chromium in an Electron.NET app #764

Closed
opened 2026-01-29 16:47:59 +00:00 by claunia · 7 comments
Owner

Originally created by @ToniTurek on GitHub (Feb 18, 2022).

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?

Originally created by @ToniTurek on GitHub (Feb 18, 2022). 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?
claunia added the question label 2026-01-29 16:47:59 +00:00
Author
Owner

@danatcofo commented on GitHub (Feb 18, 2022):

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.

@danatcofo commented on GitHub (Feb 18, 2022): 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.
Author
Owner

@ToniTurek commented on GitHub (Feb 18, 2022):

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?

@ToniTurek commented on GitHub (Feb 18, 2022): 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?
Author
Owner

@danatcofo commented on GitHub (Feb 18, 2022):

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.

@danatcofo commented on GitHub (Feb 18, 2022): 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.
Author
Owner

@ToniTurek commented on GitHub (Feb 18, 2022):

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?

@ToniTurek commented on GitHub (Feb 18, 2022): 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?
Author
Owner

@danatcofo commented on GitHub (Feb 18, 2022):

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

@danatcofo commented on GitHub (Feb 18, 2022): 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
Author
Owner

@ToniTurek commented on GitHub (Feb 19, 2022):

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:
grafik

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...

@ToniTurek commented on GitHub (Feb 19, 2022): 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: ![grafik](https://user-images.githubusercontent.com/51363132/154813355-b6aec83a-29f9-4c0e-9353-529bc040180a.png) 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...
Author
Owner

@danatcofo commented on GitHub (Feb 19, 2022):

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.

@danatcofo commented on GitHub (Feb 19, 2022): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#764