Setting browser window position causes incorrect default window options to be set #421

Closed
opened 2026-01-29 16:39:07 +00:00 by claunia · 5 comments
Owner

Originally created by @ddaspit on GitHub (Nov 29, 2019).

Originally assigned to: @GregorBiswanger on GitHub.

  • Version: 5.30.1
  • Target: Windows 10

If the X and Y properties are set when creating a browser window, then some of the default values for properties in BrowserWindowOptions are set incorrectly. The most noticeable issue is that the default font size is no longer correct (16) and set to a very small value (6). This occurs because the CreateWindowAsync method in WindowManager disables ignoring default values during serialization when X and Y are set. Many of the primitive properties in BrowserWindowOptions and WebPreferences (such as DefaultFontSize) do not have the correct default values set. A possible solution might be to re-enable ignoring default values and adding [DefaultValue(-1)] attribute to the X and Y properties in BrowserWindowOptions.

Also, when setting the position of the window on Windows 10, CreateWindowAsync subtracts 7 from the X property. This seems to be added to correct for a bug in Electron. On my Windows 10 machine, this results in the window being incorrectly positioned too far to the left. For example, if I set the X to 0, a small amount of the left side of the window is off of the screen. If I set X to 7, the window is positioned exactly on the left side of the screen. It might be worth checking if the Electron bug is still an issue. Right now, I have to add 7 to X in order to get the correct position.

Steps to Reproduce:

  1. Set X and Y in the BrowserWindowOptions when calling CreateWindowAsync.
  2. Start the app.
  3. The default font size is too small in the browser window.
Originally created by @ddaspit on GitHub (Nov 29, 2019). Originally assigned to: @GregorBiswanger on GitHub. <!-- Please search existing issues to avoid creating duplicates. --> <!-- Which version of Electron.NET CLI and API are you using? --> <!-- Please always try to use latest version before report. --> * **Version**: 5.30.1 <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> <!-- What target are you building for? --> * **Target**: Windows 10 <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> If the `X` and `Y` properties are set when creating a browser window, then some of the default values for properties in `BrowserWindowOptions` are set incorrectly. The most noticeable issue is that the default font size is no longer correct (16) and set to a very small value (6). This occurs because the `CreateWindowAsync` method in `WindowManager` disables ignoring default values during serialization when `X` and `Y` are set. Many of the primitive properties in `BrowserWindowOptions` and `WebPreferences` (such as `DefaultFontSize`) do not have the correct default values set. A possible solution might be to re-enable ignoring default values and adding `[DefaultValue(-1)]` attribute to the `X` and `Y` properties in `BrowserWindowOptions`. Also, when setting the position of the window on Windows 10, `CreateWindowAsync` subtracts 7 from the `X` property. This seems to be added to correct for a bug in Electron. On my Windows 10 machine, this results in the window being incorrectly positioned too far to the left. For example, if I set the `X` to `0`, a small amount of the left side of the window is off of the screen. If I set `X` to `7`, the window is positioned exactly on the left side of the screen. It might be worth checking if the Electron bug is still an issue. Right now, I have to add `7` to `X` in order to get the correct position. Steps to Reproduce: 1. Set `X` and `Y` in the `BrowserWindowOptions` when calling `CreateWindowAsync`. 2. Start the app. 3. The default font size is too small in the browser window.
claunia added the bug label 2026-01-29 16:39:07 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (Dec 3, 2019):

I have tried it with the latest Electron.NET version (7.30.2). For me, the window position works and the font stays in the default size.

Task.Run(async () =>
{
    var browserWindowOptions = new BrowserWindowOptions 
    {
        X = 0,
        Y = 0
    };

    await Electron.WindowManager.CreateWindowAsync(browserWindowOptions);
});

image

@GregorBiswanger commented on GitHub (Dec 3, 2019): I have tried it with the latest Electron.NET version (7.30.2). For me, the window position works and the font stays in the default size. ``` Task.Run(async () => { var browserWindowOptions = new BrowserWindowOptions { X = 0, Y = 0 }; await Electron.WindowManager.CreateWindowAsync(browserWindowOptions); }); ``` ![image](https://user-images.githubusercontent.com/7336300/70058917-18bb3100-15e0-11ea-8c36-4163c968723b.png)
Author
Owner

@ddaspit commented on GitHub (Dec 4, 2019):

I forked and updated the music player sample app to demonstrate the issue. I set the X and Y properties to 0 in the issue345 branch. With the X and Y properties set, I get:
issue345
Without the X and Y properties set (the master branch), I get:
master

@ddaspit commented on GitHub (Dec 4, 2019): I forked and updated the [music player sample app](https://github.com/ddaspit/electron.net-musicplayer-sample) to demonstrate the issue. I set the `X` and `Y` properties to `0` in the [issue345](https://github.com/ddaspit/electron.net-musicplayer-sample/tree/issue345) branch. With the `X` and `Y` properties set, I get: ![issue345](https://user-images.githubusercontent.com/3261883/70120036-2c2cd180-169e-11ea-9125-40e95be35cea.png) Without the `X` and `Y` properties set (the master branch), I get: ![master](https://user-images.githubusercontent.com/3261883/70120129-61392400-169e-11ea-8feb-fdf6e9d2a7cc.png)
Author
Owner

@GregorBiswanger commented on GitHub (May 10, 2020):

Fixed and use the new Electron.NET 8.31.1.

@GregorBiswanger commented on GitHub (May 10, 2020): Fixed and use the new Electron.NET 8.31.1.
Author
Owner

@duncanawoods commented on GitHub (Aug 13, 2020):

@GregorBiswanger I'm seeing this problem in 9.31.2.0. If I set the browser window size, fonts using rem become tiny. Can you please point me towards the cause and the commit that fixed it last time and I'll try to fix it?

@duncanawoods commented on GitHub (Aug 13, 2020): @GregorBiswanger I'm seeing this problem in 9.31.2.0. If I set the browser window size, fonts using rem become tiny. Can you please point me towards the cause and the commit that fixed it last time and I'll try to fix it?
Author
Owner

@duncanawoods commented on GitHub (Aug 13, 2020):

@GregorBiswanger The problem in WindowManager.cs, if the position is set then it uses a different serialiser for the BrowserWindowOptions:

var ownjsonSerializer = new JsonSerializer()
{
    ContractResolver = new CamelCasePropertyNamesContractResolver(),
    NullValueHandling = NullValueHandling.Ignore
};

However, not all default values are set:

/// <summary>
/// Defaults to 16.
/// </summary>
public int DefaultFontSize { get; set; }

Setting this value seems to fix the issue but we need to 100% certain all the option defaults are correct.

@duncanawoods commented on GitHub (Aug 13, 2020): @GregorBiswanger The problem in `WindowManager.cs`, if the position is set then it uses a different serialiser for the BrowserWindowOptions: ``` var ownjsonSerializer = new JsonSerializer() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore }; ``` However, not all default values are set: ``` /// <summary> /// Defaults to 16. /// </summary> public int DefaultFontSize { get; set; } ``` Setting this value seems to fix the issue but we need to 100% certain all the option defaults are correct.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#421