How do you get webpage size from the browser window?


BrowserWindow.getSize() returns the size of the window, including the window’s chrome. I need to know the size of the web page in the window (the size of the window minus the chrome).

Is there a way to get the size of the web page that’s inside the window?


It sounds like you’re looking for the viewport size. If so, you can refer to this StackOverflow answer.


I was trying to resize an HTML Canvas element to snugly in the browser window’s content area when the user resizes the window.

I ended up setting the browser window’s useContentSize to true. Then, when I call BrowserWindow.getSize() in response to a window resize, I subtract the content size from the window size to get the dimensions of the window’s chrome. Once I have the chrome dimensions, I subtract them from the window size on every resize to calculate the new canvas size.

It’s a roundabout way to get the webpage size, but it seems to work. It would be nice if BrowserWindow had a method that returns the size of the webpage.


Will document.body.clientWidth and document.body.clientHeight work? They’re supposed to return the width and height of the web page.