innerHeight is incorrect and frozen
Nakilon opened this issue · comments
br = Ferrum::Browser.new # no matter :headless true or false
br.evaluate "[innerHeight, outerHeight]"The innerHeight is expected to be smaller than outerHeight: https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
But in fact they are equal and innerHeight is frozen (at 768). When I resize the window it does not change.
Also because of this the third-party JS scripts are unable to correctly obtain the client area and resize the content beyond it.
v 0.11, macOS Big Sur
I've commented this out
Lines 104 to 109 in 7f37640
These are params that are passed to Emulation.setDeviceMetricsOverride except slowmoable. Could you write a failing test?
except
slowmoable
I don't see fitwiondow neither. I guess it's just outdated. I tried to find what's the point of this command at all but it dates to the first commit of the repo.
Could you write a failing test?
I suppose the simplest assertion is that innerHeight should be smaller than outerHeight in non-fullscreen mode that should be true for any browser.
Other than that probably more reliable would be to craft a HTML page with a node absolutely positioned from 0 to inner... and maybe Ferrum provides a method to see if the node is fully visible. Or maybe if there is only a method to check partial visibility then to craft 4 lines just outside and inside the borders of the rect. Unless these methods depend on the malfunctioning inner...` in the first place
Or maybe try to issue a mouse click event on a positioned element -- pretty sure it won't work if the element is really outside.
I thought about creating a 1x1 pixel buttons to test if they are clickable but if you zoom it you'd see that buttons are catching the click event on a larger area even with CSS styles applied to make them rectangle and small.
Then I thought that you could screenshot a page and see (with help of chunky_png that is already in the Gemfile) how the rectangle drawn within inner isn't taking all the window space but it appeared that ferrum's screenshot thing is taking exactly the html or body tag size and does not have a clue the real window was larger. (btw, the addition to the initial report: the simplest way to see that it's bugged is that when you resize the window the page remains intact, because those sizes are frozen for the html page runtime). So the only way to screenshot the issue is on the OS level.
P.S.: the "allows the window to be positioned" in bundle exec rspec spec/browser_spec.rb fails on my machine because the initial coordinates appear to be not (0,0) and I'm not sure why the tests even assume that. AFAIK when I was adding/editing those tests I explicitly wrote them in a way that does not assume the starting coordinates, idk why it was changed.
Another thing I see (called binding.irb at the start of some test) is that the things are fixed right after any programmatic resizing:
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff5c82718f0>):002:0> browser.evaluate "[innerHeight, outerHeight]"
=> [768, 768]
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff5c82718f0>):003:0> browser.evaluate "[innerWidth, outerWidth]"
=> [1024, 1024]
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff5c82718f0>):004:0> browser.resize width: 100, height: 100
=> {}
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff5c82718f0>):005:0> browser.evaluate "[innerWidth, outerWidth]"
=> [100, 514]
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff5c82718f0>):006:0> browser.evaluate "[innerHeight, outerHeight]"
=> [100, 385]
UPD: nevermind, it's just because of the minimal possible window size. If you increase the window, you'd see the issue is still there:
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff4b02d6110>):030:0> browser.resize width: 2000, height: 1400
=> {}
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff4b02d6110>):031:0> browser.evaluate "[innerWidth, outerWidth]"
=> [2000, 2000]
irb(#<RSpec::ExampleGroups::FerrumBrowser:0x00007ff4b02d6110>):032:0> browser.evaluate "[innerHeight, outerHeight]"
=> [1400, 1400]
I would just delete that line if it does not break anything. As I said I see no reason why it's even there, since it's in the first commit. While it breaks the websites layout in the way that page does not fit the window and people have to scroll the page that would not be needed in a normal browser. At least on the headfull macOS. I see no way to fully test it without going to OS level screenshotting, and if not that then:
I suppose the simplest assertion is that innerHeight should be smaller than outerHeight in non-fullscreen mode that should be true for any browser.
OS level screenshotting
For example, craft an html page with with 4 colored pixels on the absolute coordinates, then find the UI element with applescript, screenshot the region and analyze with some chunkypng. Can be done on headfull macOS.