electron: BrowserWindow.getContentSize() does not behave the same as expected

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 10.1.0
  • Operating System:
    • windows 10
  • Last Known Working Electron version:
    • 9.0.x

In some cases,I need to change the height of the windwo and keep the width the same. when I use

let win = BrowserWindow.getAllWindows()[0]
let size = win.getContentSize() //or let size = win.getSize()
win.setSize(Math.floor(size[0]),1000)

then width will excatly +1 when I call these code (in another case,the height will excatly +1 also)

It looks the getContentSize always get 1px more then window.

Even though I can simply -1 after I get the size of the window,I still want kown why

Expected Behavior

window.getContentSize() should return the excat px of the window

Actual Behavior

window.getContentSize() get 1px more on both width and height

To Reproduce

Screenshots

image image

Additional Information

getSize() will behave the same as getContentSize()

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

@lmx-Hexagram and @ColorfulHorse I am having a bit of trouble recreating your issues. Could you try running this Fiddle gist and confirm whether or not you are experiencing the same thing?: Gist If not, if you could create and link your own gist, that would be very helpful. (I housed both of your examples in the same gist, so the code under “IPC Method” can be commented out in favor of “Remote Method” and vice versa. )

the window width is 850, but window.getSize return 851

this.win = new BrowserWindow({
            maximizable: false,
            fullscreen: false,
            frame: false,
            transparent: true,
            focusable: true,
            width: 850,
            height: 200,
            resizable: true,
            movable: true,
            closable: true,
            skipTaskbar: true,
            webPreferences: {
                nodeIntegration: Boolean(process.env.ELECTRON_NODE_INTEGRATION),
                nodeIntegrationInWorker: true,
                enableRemoteModule: true,
                webSecurity: false
            },
            show: false
        })
mounted() {
    const win = remote.BrowserWindow.getFocusedWindow()
    if (win) {
      const { width, height } = win.getSize() // width = 851
    }
}