rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.7k stars 122 forks source link

Emulation.setDeviceMetricsOverride causes wrong scale to be used for screenshots #330

Closed aaronjensen closed 1 year ago

aaronjensen commented 1 year ago

On a high DPI screen, where window.devicePixelRatio is 2, for example, taking screenshots should use a scale of 2. It would, by default if it weren't for the fact that Emulation.setDeviceMetricsOverride is invoked, setting the deviceScaleFactor to 1. It's unclear why this is necessary, as both headed and headless mode appear to work without it.

Furthermore, if you take a screenshot during headed mode and deviceScaleFactor is reduced to 1, it causes an unsightly flash as Chrome scales the viewport down by half before taking the screenshot.

It also seems to be related to and/or cause this issue: https://github.com/rubycdp/ferrum/issues/203

Is the line necessary at all or can it be removed?

Thanks!