How to properly configure window width and height?

261 views
Skip to first unread message

xivan...@gmail.com

unread,
Jul 31, 2017, 7:00:43 AM7/31/17
to headless-dev
Hello,

i'm trying to configure width and height of the opened tab window, but seems that my changes almost has no effect (i.e. it affects only screenshots viewport).

➜  chrome-linux ./chrome --version
Chromium 62.0.3173.0 

➜  chrome-linux lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial

Steps to reproduce:

=> {"id":1, "method":"Target.createTarget", "params":{ "url":"about:blank", "width":1024, "height":768 } }
<= {"id":1, "result":{"targetId":"2ed8ea7a-ed8a-4ad4-94d4-82799ea5a32d"}}
=> {"id":2, "method":"Emulation.setDeviceMetricsOverride", "params":{"width":1024, "height":768,"screenWidth":1024,"screenHeight":768, "deviceScaleFactor": 1, "mobile": false}}
=> {"id":3, "method":"Emulation.setVisibleSize", "params":{"width":1024,"height":768}}
=> {"id":4, "method":"Page.navigate", "params":{"url": "http://ya.ru"}}
wait 5 seconds
=> {"id":5, "method":"Runtime.evaluate", "params":{"expression": "window.screen.width"}}
<= {"id":5,"result":{"result":{"type":"number","value":800,"description":"800"}}}
=> {"id":6, "method":"Runtime.evaluate", "params":{"expression": "window.screen.height"}}
<= {"id":6,"result":{"result":{"type":"number","value":600,"description":"600"}}}
=> {"id":7, "method":"Runtime.evaluate", "params":{"expression": "window.screen.availWidth"}}
<= {"id":7,"result":{"result":{"type":"number","value":800,"description":"800"}}}
=> {"id":8, "method":"Runtime.evaluate", "params":{"expression": "window.screen.availHeight"}}
<= {"id":8,"result":{"result":{"type":"number","value":600,"description":"600"}}}

In other words i'm trying to create a target with w/h = 1024/768, then calling Emulation.setDeviceMetricsOverride and Emulation.setVisibleSize with same w/h and screen w/h, but getting 800/600 in JS window.screen obj.

Eric Seckler

unread,
Jul 31, 2017, 8:27:41 AM7/31/17
to xivan...@gmail.com, headless-dev

Hm, does window.innerWidth/Height change to the correct values?


--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/aec4a770-f353-41c6-b213-299711fb9a2c%40chromium.org.

Alex Clarke

unread,
Jul 31, 2017, 8:35:31 AM7/31/17
to Eric Seckler, xivan...@gmail.com, headless-dev
This is because RenderWidget::GetScreenInfo does not know about the device metrics override (it should). 

To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

To post to this group, send email to headle...@chromium.org.

Alex Clarke

unread,
Jul 31, 2017, 8:45:00 AM7/31/17
to Eric Seckler, xivan...@gmail.com, headless-dev
Actually scratch that, there's something more complex going on.  As it happens I'm debugging a similar problem and naively altering RenderWidget::GetScreenInfo  breaks some layout tests (although it did fix my problem).

Alex Clarke

unread,
Jul 31, 2017, 8:59:42 AM7/31/17
to Eric Seckler, xivan...@gmail.com, headless-dev
It looks like screen_width & screen_height are only overridden when emulating a mobile device.  I don't really know why that's the case.

Eric Seckler

unread,
Jul 31, 2017, 9:11:00 AM7/31/17
to Alex Clarke, headless-dev, xivan...@gmail.com, pfel...@chromium.org, Dmitry Gozman
+dgozman, pfeldman


To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

To post to this group, send email to headle...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

To post to this group, send email to headle...@chromium.org.

Dmitry Gozman

unread,
Jul 31, 2017, 1:36:16 PM7/31/17
to Eric Seckler, Alex Clarke, headless-dev, xivan...@gmail.com, Pavel Feldman
Here is what protocol says:
{ "name": "screenWidth", "type": "integer", "optional": true, "experimental": true, "description": "Overriding screen width value in pixels (minimum 0, maximum 10000000). Only used for |mobile==true|." },

The reason for it is historical, but we can certainly support it in desktop emulation as well. Mind making a patch (look at RenderWidgetScreenMetricsEmulator::Apply)?

Thanks,
Dmitry

+dgozman, pfeldman


To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

To post to this group, send email to headle...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

Alex Clarke

unread,
Jul 31, 2017, 4:17:28 PM7/31/17
to Dmitry Gozman, Eric Seckler, headless-dev, xivan...@gmail.com, Pavel Feldman
I was writing a patch earlier :)  Is the current desktop behavior important? (There don't seem to be any layout tests for it) Should we just make it do the same thing as mobile always or should we add a new flag to control desktop behavior?
Message has been deleted
Message has been deleted

Dmitry Gozman

unread,
Jul 31, 2017, 6:17:32 PM7/31/17
to Alex Clarke, Eric Seckler, headless-dev, xivan...@gmail.com, Pavel Feldman
Just make it similar to mobile, preserving existing values if I didn't pass anything and overriding otherwise.

- Dmitry

xivan...@gmail.com

unread,
Jul 31, 2017, 10:55:11 PM7/31/17
to headless-dev, alexc...@google.com, esec...@chromium.org, xivan...@gmail.com, pfel...@chromium.org, dgo...@chromium.org
Eric Seckler, i have re-checked and can confirm that window.innerWidth/Height was changed to correct values.

Also while trying this stuff i have found a bug - 
  if Emulation.setDeviceMetricsOverride was called with deviceScaleFactor = 0 then Page.captureScreenshot method hangs (or fails silently).

According to docs deviceScaleFactor "0 disables the override."

ws dump:

=> {"id":1, "method":"Target.createTarget", "params":{ "url":"about:blank", "width":1024, "height":768 } }
<= {"id":1, "result":{"targetId":"2ed8ea7a-ed8a-4ad4-94d4-82799ea5a32d"}}
=> {"id":2, "method":"Emulation.setDeviceMetricsOverride", "params":{"width":1024, "height":768,"screenWidth":1024,"screenHeight":768, "deviceScaleFactor": 0, "mobile": false}}
=> {"id":3, "method":"Page.navigate", "params":{"url": "http://ya.ru"}}
wait 5 seconds
=> {"id":4, "method":"Page.captureScreenshot", "params":{}}

It's not crucial but counter intuitive as per docs 0 looks like a good default value.
+dgozman, pfeldman


To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

To post to this group, send email to headle...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

Sami Kyostila

unread,
Aug 15, 2017, 3:09:12 PM8/15/17
to xivan...@gmail.com, headless-dev, alexc...@google.com, esec...@chromium.org, pfel...@chromium.org, dgo...@chromium.org
Reply all
Reply to author
Forward
0 new messages