Deep Dive about viewport sizes

Halp! XD I decided to tinker around trying to get a better understanding of the viewport's size. Just for better understanding. I thought it would be simple. But it seems i was a tid bit wrong. I have two ways from the js window object ill refer to as inner and outer. From what i understand, inner is more or less the viewport itself. And outer is the whole application browser(viewport + chrome(the tab and search bar. Very weird name choices here.)) inner width,height seem to work well! I tested by making a new window via window.open:
window.open('', 'myPopup', 'width=500,height=500,left=100,top=100');
window.open('', 'myPopup', 'width=500,height=500,left=100,top=100');
The goal, a 500x500 window for example sake. It makes a window with this as result:
InnerWindow: 508 x 518
Outer Window: 522 x 590
InnerWindow: 508 x 518
Outer Window: 522 x 590
It appears 8 was added to the width, and 18 added to the height. And how i measured this was making a div in another window that same size. And as you can see, they match up pretty well. Not sure why it added 8 and 18 however.
No description
15 Replies
DemonSlayer112
DemonSlayer112OP5mo ago
But what makes it weirder? See the outer size? 522 x 590? First off it changes by 1 if you move the window. 522 x 590 over here moves it 523 x 591 over there, i assume this is viewport pixel rounding error stuff. Anyways. The numbers are wrong.
No description
DemonSlayer112
DemonSlayer112OP5mo ago
The next div is 520 x 590 as well, but as you can see, its not the same size of the browser at all. I assumed "hey maybe its invisible scrollbars" but that doesnt explain the sliver at the bottom So the main points of confusion is why width and height adds 8 and 18 for inner. And why it adds 22 and 90 for outer(Which is specially odd considering the width of window actually shouldnt be that different)
ἔρως
ἔρως5mo ago
borders and browser's chrome (in this context, the "chrome" is the browser ui and not google chrome itself) also, if i had to bet, there is some weirdness with sub-pixel rendering too
DemonSlayer112
DemonSlayer112OP5mo ago
this bit right?
No description
ἔρως
ἔρως5mo ago
and the border around the window it is 1 or 2 pixels
DemonSlayer112
DemonSlayer112OP5mo ago
but that doesnt account for the 508 -> 522 right?
ἔρως
ἔρως5mo ago
for the width or height?
DemonSlayer112
DemonSlayer112OP5mo ago
the width
ἔρως
ἔρως5mo ago
yes, it does: the scrollbar is 17 pixels or something like that 🤔 actually, let me check
DemonSlayer112
DemonSlayer112OP5mo ago
outer - inner gives 15 which maybe 16 or 14 from the rendering thing
ἔρως
ἔρως5mo ago
i just checked and the sidebar is indeed 15px on windows 11 it may also be a bug
DemonSlayer112
DemonSlayer112OP5mo ago
wait so inner only accounts for scrollbar if rendered correct? Thats what i been seeing said around, and if the window goes from 500x500 initally to be instead to 508 x 518, where does this 8 and 18 come from? I get if its borders and scrollbars but is the bottom scroll bar different or something? The additional size is over double Ok so now im thinking thats possibly a weird size restrant on the window.open function. Idk why...but if its too small it will add 8 and 18. But if its say
window.open('', 'myPopup', 'width=700,height=700');
window.open('', 'myPopup', 'width=700,height=700');
The result is surprisingly:
InnerWindow: 686 x 663
Outer Window: 700 x 700
InnerWindow: 686 x 663
Outer Window: 700 x 700
didnt add 22px to the outer width this time
DemonSlayer112
DemonSlayer112OP5mo ago
Perhaps outer width...doesnt include scrollbar?
No description
DemonSlayer112
DemonSlayer112OP5mo ago
700px div doesnt match the 700px outer claims to be
ἔρως
ἔρως5mo ago
https://developer.mozilla.org/en-US/docs/Web/API/Window/outerWidth <-- it includes everything instead of 700x700, try 700x720

Did you find this page helpful?