New issue
Advanced search Search tips

Issue 778141 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Chrome
Pri: 2
Type: Bug



Sign in to add a comment

window.open width/height is not interpreted as CSS pixels

Reported by steffen....@gmail.com, Oct 25 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36

Steps to reproduce the problem:
1. Configure Windows to use 150% scaling.
2. Configure Chrome to use 200% scaling.
3. window.open( 'test.html', new Date().getTime(), 'width=600, height=300' );

What is the expected behavior?
The resulting window window should have 
  window.innerWidth == 600 && window.innerHeight == 300

https://drafts.csswg.org/cssom-view/#the-features-argument-to-the-open()-method

What went wrong?
window.open measures width and height in "windows pixels" instead of CSS pixels.

If the window contains a image with 600px x 300px it will not fit.

First test:
  window.open( 'test.html', new Date().getTime(), 'width=600, height=300' );

Windows Chrome Result (innerWidth x innerHeight)
 100%    100%    600 x 300 (correct)
 100%    200%    400 x 200 (incorrect)
 150%    100%    602 x 302 (almost correct)
 150%    200%    301 x 151 (incorrect)

The problem can be shifted:

window.open( 'test.html', new Date().getTime(), 'width=' + ( 600 * devicePixelRatio ) + ', height=' + ( 300 * devicePixelRatio ) );

Windows Chrome Result (innerWidth x innerHeight)
 100%    100%    600 x 300 (correct)
 100%    200%    600 x 300 (correct)
 150%    100%    902 x 452 (incorrect)
 150%    200%    901 x 451 (incorrect)

So the solution can either handle windows scaling or chrome scaling but not both.

Did this work before? N/A 

Chrome version: 61.0.3163.100  Channel: n/a
OS Version: 10.0
Flash Version: 

If there was a way to detect the scale factor of chrome or windows independently, the problem would be easy to solve.
However I only found devicePixelRatio which gives the product of windows and chrome scaling (i.e. 3.0 if windows is at 150% and chrome is at 200%).
 
test.html
407 bytes View Download

Comment 1 by rbyers@chromium.org, Oct 26 2017

Cc: bokan@chromium.org
Components: -Blink Blink>WindowDialog
Labels: OS-Chrome OS-Linux
Status: Untriaged (was: Unconfirmed)
Summary: window.open width/height is not interpreted as CSS pixels (was: window.open does not correctly apply dimensions)
I verified that on Chrome Linux 63.0.3236.7 the width/height arguments are interpreted as DIPs, which appears to violate the CSS spec.

I also verified that Firefox 56.0 correctly interprets them as CSS pixels (though the repro still doesn't quite work - window.innerWidth appears to not initially take the page zoom into account at the time the script is running).

Comment 2 by rbyers@chromium.org, Oct 26 2017

Labels: Hotlist-Interop

Comment 3 by bokan@chromium.org, Oct 26 2017

Cc: -bokan@chromium.org
Owner: bokan@chromium.org
Status: Assigned (was: Untriaged)
Firefox and Internet Explorer work correctly on Windows 10.
Chrome and Edge behave equally incorrect.

Is there a workaround? devicePixelRatio only helps for browser scaling but makes windows scaling even worse... I did not find a way to detect windows pixel scaling from within the browser. It would also help to detect browser scaling alone (devicePixelRatio / browser scaling = windows scaling)...

Comment 5 Deleted

Sign in to add a comment