Skip to content

[Breaking Change] 41.3 + 42: frameless+thickFrame HWND grows 16×8 DIP, no longer matches getBounds() #51679

Open

Description

@gdavidkov

Preflight Checklist

Electron Version

42.1.0

What operating system(s) are you using?

Windows

Operating System Version

Windows 11 (verified on 10.0.22631 and 10.0.26200)

What arch are you using?

x64

Last Known Working Electron version

41.2.0

Does the issue also appear in Chromium / Google Chrome?

I don't know how to test

Expected Behavior

For BrowserWindow({ frame: false, thickFrame: true, resizable: true }) on Windows, the on-screen HWND rect (read via user32!GetWindowRect) equals screen.dipToScreenRect(win.getBounds()). setBounds({ x, y, width: W, height: H }) produces a visible window of W × H DIP at (x, y). This held through Electron 41.3.0.

Actual Behavior

Starting in 41.3.0 (backport of #50706 via #50863) and 42.0.0 (via #50864), the HWND extends outward from getBounds() by SM_CXSIZEFRAME + SM_CXPADDEDBORDER DIP on left, right, and bottom, and by 0 on top. setBounds({ x, y, width: W, height: H }) produces a visible window of (W + 16) × (H + 8) DIP at (x - 8, y) at 100% DPI (scales with DPI). getBounds(), getNormalBounds(), and getContentBounds() continue to return the original logical (inset-subtracted) rect, so the getBounds() ↔ HWND identity is broken on this window class. No constructor option, runtime flag, or JS API to query the inset or restore pre-41.3 behavior.

Testcase Gist URL

https://gist.github.com/gdavidkov/c8c466109c009ff195f1abdcb68362a9

Additional Information

How the break looks in numbers

Same BrowserWindow options, same display, measured locally with the repro at the bottom of this issue:

Observation Electron 41.2.0 (last working) Electron 41.3.0 / 42.1.0 (same input) Delta
asymmetricInsetPhysical @ 100% DPI {0, 0, 0, 0} {left:8, top:0, right:8, bottom:8} new inset
asymmetricInsetPhysical @ 137.5% DPI {0, 0, 0, 0} {left:12, top:0, right:12, bottom:11} new inset (scales with DPI)
Visible window width for setBounds(w:500) 500 DIP 516 DIP +16 DIP
Visible window height for setBounds(h:400) 400 DIP 408 DIP +8 DIP
getBounds() vs HWND rect identical HWND = bounds outset by TLBR(0, T, T, T) identity broken
Center of getBounds() vs HWND center on Y identical logical center is T/2 above HWND center −4 DIP
setBounds(display.workArea) fills workArea yes overflows workArea by T DIP on L / R / B window leaves work area

Source of the change

Introduced by #50706 "fix: external resize hit targets for frameless windows on Windows" (shipped as #50864), with follow-up regression fix in #51252 / #51296. The relevant code in shell/browser/ui/views/[email protected]:

gfx::Insets WinFrameView::RestoredFrameBorderInsets() const {
  if (window_->has_frame() || !window_->has_thick_frame() ||
      !window_->IsResizable())
    return {};

  const int thickness =
      display::win::GetScreenWin()->GetSystemMetricsInDIP(SM_CXSIZEFRAME) +
      display::win::GetScreenWin()->GetSystemMetricsInDIP(SM_CXPADDEDBORDER);
  return gfx::Insets::TLBR(0, thickness, thickness, thickness);
}

Related

Activity

  1. added theissue type on May 18, 2026
  2. added
    has-repro-gist
    on May 18, 2026
  3. moved this to 👀 Unsorted Items in 42-x-yon May 18, 2026
  4. nikwen commented on May 18, 2026

    @nikwen
    Member

    Thanks for reporting!

    As far as I understand, that change was intentional. I'm not sure we ever guaranteed getBounds() ↔ HWND identity.

    @mitchchn knows this part of the code better. Maybe he has some ideas on how to get the outer bounds.

    What do you need the outer bounds for?

  5. gdavidkov commented on May 19, 2026

    @gdavidkov
    ContributorAuthor

    Thanks @nikwen!

    To your second question first — I don't strictly need outer bounds; what I need is for setBounds(R) and getBounds() to refer to the same rectangle the user actually sees. Exposing the inset is one possible fix, but restoring the round-trip (or making setBounds outset-aware) would work equally well. The concrete things that break under the new behaviour, all on a frame:false, thickFrame:true, resizable:true window:

    • setBounds(display.workArea) no longer fills the work area — it overflows by the inset on L/R/B (16×8 DIP at 100% DPI, more at higher DPI). Any custom "maximize into work area" implementation is now wrong by that amount.
    • Snap-to-edge / tiling / docking against display edges or other windows: there's no way to place a frameless window flush against an edge via setBounds, because the visible window extends past the rect you passed in.
    • Multi-window layouts — e.g. docking a palette to the right edge of a main window via child.x = parent.x + parent.width now leaves a gap on one side and overlaps on the other (asymmetric inset: 0 on top, T on L/R/B).
    • Persist-and-restore window geometry (getBounds() → save → setBounds() on next launch) is no longer a fixed point: each restart shifts the window outward by the inset.
    • Automation / capture / e2e tests that read the HWND rect and reconcile it against getBounds() are now off by the inset with no API to bridge the two.

    On "I'm not sure we ever guaranteed getBounds() ↔ HWND identity" — fair that it may not have been a formal contract, but it held for the entire history of the API until 41.3, and the setBounds/getBounds docs describe them as the window's bounds, not a logical rectangle that diverges from what's on screen. If this is intentional, it's a breaking change for frameless apps that do their own window management, and at minimum I'd expect a note in the breaking-changes doc and some API to query the inset — right now it has to be reverse-engineered from SM_CXSIZEFRAME + SM_CXPADDEDBORDER per-monitor DPI, which apps shouldn't have to do.

    Happy to test any fix on 41-x-y / 42-x-y / main.

  6. nikwen commented on May 19, 2026

    @nikwen
    Member
    1. Please don't send us AI-generated comments (or code).
    2. "what I need is for setBounds(R) and getBounds() to refer to the same rectangle the user actually sees": It seems to me like the x coordinate is 5 pixels off in my testing. Gist: https://gist.github.com/1926b6534e90feb4a0cfd947c5da3a9b
  7. mitchchn commented on May 19, 2026

    @mitchchn
    Member

    Thanks @gdavidkov.

    what I need is for setBounds(R) and getBounds() to refer to the same rectangle.

    Agreed. This is something we can work toward if it's not currently the case. What would help the most are gists demonstrating the edge cases and your expectations.

    Let me address some of your other feedback:

    On "I'm not sure we ever guaranteed getBounds() ↔ HWND identity" — fair that it may not have been a formal contract, but it held for the entire history of the API until 41.3.

    Introducing insets can have one of two consequences. Either: 1) window bounds suddenly change, since they now include insets or 2) window bounds stay the same as before, but are computed from a different rectangle.

    We opted for 2) to best preserve expectations for most people, especially since Electron's main use case is cross-platform apps.

    A developer who creates an 800x600 frameless window would not expect the window to be smaller or located in a different position in Electron 41.3 compared to 41.2.

    Perhaps more importantly, developers would not expect their frameless window to be smaller on Windows than it is on Mac. There is no reasonable way to manage the difference between platforms if window bounds include insets.

    No constructor option, runtime flag, or JS API to query the inset or restore pre-41.3 behavior.

    Bugs aside (which I agree with you we must fix), there are several alternatives: if you do not want insets at all, you can set thickFrame: false as before. This was already the best configuration for any app that needs to fill the work area in custom way or to have a level of precision that doesn't depend on OS decorations.

    And if you still need access to the HWND specifically, you can get it with win.getNativeWindowHandle() and run whatever Windows-specific logic you need.

  8. estoykov commented on May 19, 2026

    @estoykov

    If we have "frame: false" and thickFrame: false", then we'll lose rounded corners and drop shadows - the things that our clients dream about - don't know why, but hey do.
    The previous approach - to have sizing areas inside the client area was an acceptable compromise in this case - sizing and the lovely rounded corners and drop shadows as I said.
    And this could be an option - either inner sizing areas or "behind the scene" insets with outer sizing.

    And talking about HWND, it will be nice to have a separate (Windows only) methods, like: setScreenBounds()/getScreenBounds().
    In fact your screenToDipRect and dipToScreenRect (again Windows only) work pretty well. So in rich desktop applications, they can be used with these two new methods to achieve correct window placement as much as possible. Now we're forced to use a dirty tricks with native modules to achieve this.
    This doesn't compensate an ability to choose between inner or outer sizing areas though.

    (screenToDipRect and dipToScreenRect don't work well when target BrowserWindow is given, but the rectangle is in a another display with different scaling - this is another story).

    About expected bounds:

    • Electron 42.2.0
    • 150% scaling
      bounds: { x: 568, y: 316, width: 800, height: 600 }
      content bounds: { x: 567, y: 316, width: 802, height: 602 }

    Cheers!

    (This is not AI generated)

    Edit: About multi-platform
    Electron is a multi-platform for a window based rich desktop applications - it really is, thank you for that! :)
    But we can't (or we shouldn't imho) to treat all platforms that Electron supports equally, because they simply are not.

    • Linux - with the latest shift to Wayland, as far as I know we can't even have a exact layout restore - setLocation is basically no-op because Wayland doesn't support it (correct me if I'm wrong).
    • macOS - Apple always knows what we need, so there are no real screen bounds, the OS takes care of scaling, positioning, etc.
    • Windows - We have everything - real display/window screen bounds, scaling, etc. Electron is already DPI aware application and receives actual screen bounds, location, etc.

    Electron code is already polymorphic with different implementations (and methods as I said above) for the different platforms. So keeping it "pure" multi-platform, at least in window management, could introduce annoying/unwanted behavior for the developers. Instead to give what underlying OS provides in order to write the code that is close to it.

  9. nikwen commented on May 19, 2026

    @nikwen
    Member

    @mitchchn You messaged me on Slack that you can't repro the offset that I'm seeing.

    Here's a screenshot using the gist from above:

    Image

    If I draw a rectangle around the window, the top left corner is at (395, 400). The bottom right corner is at (1205, 1205).

    These are my display settings:

    Image

    The CLI output of the gist is as expected:

    { x: 200, y: 200, width: 400, height: 400 }
    
  10. yuzw1007 commented on May 20, 2026

    @yuzw1007

    这个应该都是那个边框改动造成的,跟我之前反馈的那个问题应该是同一个原因引起的,我反馈的那个问题最后一个正常工作版本:41.2.0,之后的版本都有这个边框问题。#51540

  11. moved this from 👀 Unsorted Items to 🔄 Follow Up Before Stable in 42-x-yon May 20, 2026
  12. mitchchn commented on May 20, 2026

    @mitchchn
    Member

    Thanks for the gist and screenshot @nikwen. When I run your gist at 100% scale, I get the same exact results as as in earlier versions of Electron (41.0). The error starts to accumulate at higher display scales. Is this something you can also confirm? If so, the issue here is likely not the bounds rect, but rounding errors between screen and DIP.

    @estoykov thank you as well for the followup. I agree with everything you say and I'm certainly not opposed to platform-specific APIs, as long as the basic ones work in a predictable way for non-experts. (That is, I hope developers don't need APIs to work around DPI/scaling/multi-monitor bugs: we needs to fix those in the framework.)

  13. nikwen commented on May 21, 2026

    @nikwen
    Member

    When I run your gist at 100% scale, I get the same exact results as as in earlier versions of Electron (41.0). The error starts to accumulate at higher display scales.

    @mitchchn I don't know how to test it to be honest. I'm running on a Parallels VM, which seems to default back to 200% even if I change it.

    Image

    It seems like a different issue than the original report about the HWND size though, so I've created a separate bug report for it here: #51730

    @mitchchn Should we replace this issue (#51679) with a feature request to expose the window insets?

  14. savely-krasovsky commented on May 26, 2026

    @savely-krasovsky
    Contributor

    We also use frameless: true and thickFrame: true + menubar. Window started to shrink every time between hide and show:

    [window-bounds] menubar:resize {
      size: { width: 254, height: 422 },
      bounds: { x: 3170, y: 962, width: 254, height: 422 }
    }
    [window-bounds] menubar:move {
      size: { width: 254, height: 422 },
      bounds: { x: 3170, y: 962, width: 254, height: 422 }
    }
    [window-bounds] menubar:move {
      size: { width: 254, height: 422 },
      bounds: { x: 3170, y: 962, width: 254, height: 422 }
    }
    [window-bounds] menubar:show {
      size: { width: 254, height: 422 },
      bounds: { x: 3170, y: 962, width: 254, height: 422 }
    }
    [window-bounds] menubar:hide {
      size: { width: 254, height: 422 },
      bounds: { x: 3170, y: 962, width: 254, height: 422 }
    }
    [window-bounds] menubar:resize {
      size: { width: 238, height: 414 },
      bounds: { x: 3186, y: 970, width: 238, height: 414 }
    }
    [window-bounds] menubar:move {
      size: { width: 238, height: 414 },
      bounds: { x: 3186, y: 970, width: 238, height: 414 }
    }
    [window-bounds] menubar:show {
      size: { width: 238, height: 414 },
      bounds: { x: 3186, y: 970, width: 238, height: 414 }
    }
    [window-bounds] menubar:hide {
      size: { width: 238, height: 414 },
      bounds: { x: 3186, y: 970, width: 238, height: 414 }
    }
    [window-bounds] menubar:resize {
      size: { width: 222, height: 406 },
      bounds: { x: 3202, y: 978, width: 222, height: 406 }
    }
    [window-bounds] menubar:move {
      size: { width: 222, height: 406 },
      bounds: { x: 3202, y: 978, width: 222, height: 406 }
    }
    [window-bounds] menubar:show {
      size: { width: 222, height: 406 },
      bounds: { x: 3202, y: 978, width: 222, height: 406 }
    }
    

    Scale is 100%, 3440x1440.

    const menuBarWindowOpts: BrowserWindowConstructorOptions = {
      width: MENUBAR_CONTENT_SIZE.width,
      height: MENUBAR_CONTENT_SIZE.height,
      // GNOME needs content sizing to avoid an undersized menu window; on Windows it makes window smaller than needed.
      useContentSize: !is.windows,
      frame: false,
    
      backgroundColor: getBackgroundColor(),
      resizable: false,
      maximizable: false,
      skipTaskbar: true,
      webPreferences: {
        preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
      },
    };
  15. moved this from 🔄 Follow Up Before Stable to 👍 Does Not Block Stable in 42-x-yon Jun 24, 2026
  16. davidfrogley-appgate commented on Jun 26, 2026

    @davidfrogley-appgate

    Hitting what looks like the same regression after upgrading from Electron 41.1 to 42.4, but with a slightly different config than the one in the title. Posting in case the additional data points help narrow the cause.

    Our config (Windows 11):

    • frame: false
    • titleBarStyle: 'hidden'
    • resizable: false ← not true as in the original report
    • No explicit thickFrame setting (Electron default)
    • Constructor: width: 375, height: 667

    What we observed at 100% DPI:

    • After new BrowserWindow({ width: 375, height: 667, resizable: false, ... }): both getSize() and getContentSize() returned 327 × 643.
    • After a follow-up mainWindow.setSize(375, 667): getSize() and getContentSize() both returned 359 × 659.
    • Same 16 DIP horizontal / 8 DIP vertical delta described in this issue, just manifesting as an under-size of the renderer instead of an over-size of the HWND.

    The relevance: the symptom in the title is frameless + thickFrame + resizable: true → HWND grows by 16×8. We're seeing frameless + resizable: false → renderer shrinks by 16×8. Same magnitude, same Electron versions, looks like the same RestoredFrameBorderInsets() accounting, applied to a different config path.

    On DPI scaling: the original report says the inset scales with DPI (12/11 at 137.5%). We tested our workaround at 100%, 125%, and 150% on Windows 11 and the rendered layout was identical at every scaling level — i.e. for the resizable: false code path the delta appears to be a constant [16, 8] DIP regardless of DPI, not DPI-scaled. Possibly worth checking whether the two code paths (resizable true vs. false) hit different inset accounting.

    Workaround we shipped (for anyone else landing here):

    const W_DELTA = process.platform === 'win32' ? 16 : 0;
    const H_DELTA = process.platform === 'win32' ? 8 : 0;
    new BrowserWindow({ width: 375 + W_DELTA, height: 667 + H_DELTA, ... });

    Verified across 100%/125%/150% DPI on Windows 11.

  17. SpoilerJones commented on Aug 14, 2026

    @SpoilerJones

    I came very close to submitting my own bug report but noticed this one at the last second thanks to the potential-duplicates detector.

    Here's the gist I made. I used that code in Electron Fiddle to confirm that 43.4.0 is still affected, and to nail down the exact version that introduced the issue.

    Electron Chromium Affected
    41.2.0 146.0.7680.179 no
    41.2.1 146.0.7680.188 yes

    41.2.1 (2026-04-16) is the first release containing #50863. (I see @mitchchn is already on board here, so sorry if this is overexplaining...)

    I'd also point out that the "outer" geometry that JS code on the page sees (window.outerWidth/outerHeight/screenLeft/screenTop) is also in disagreement with getBounds. This is biting my app where we have a fair number of pages shown in floating windows whose JS reads their bounds to save it to the DB (behind the web server) and restore those bounds on next launch. I have a workaround, but it's pretty sweaty and I'd love to get rid of it.

  18. Nantris commented on Oct 6, 2026

    @Nantris
    Contributor

    Any update on this? This is a big headache and a bummer to be dealing with and it requires lots of bandaids in JS to mitigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    42-x-ybug 🪲component/BrowserWindowhas-repro-gistplatform/windows

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions