Class: Dommy::Screen
- Inherits:
-
Object
- Object
- Dommy::Screen
- Includes:
- Bridge::Methods
- Defined in:
- lib/dommy/screen.rb
Overview
window.screen — the Screen interface. A headless browser has no physical
display, so the screen reports the (approximate) viewport size, with standard
desktop colour depth and an orientation derived from the aspect ratio.
window.screen is always present in a real browser, and screen.width /
screen.height are routinely read unguarded (analytics, responsive logic),
so a missing screen makes them throw "cannot read property 'width' of
undefined" — which is exactly what real sites hit when Dommy lacked it.
Instance Method Summary collapse
- #__js_call__(method, _args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #__js_set__(_key, _value) ⇒ Object
-
#initialize(window) ⇒ Screen
constructor
A new instance of Screen.
Methods included from Bridge::Methods
Constructor Details
#initialize(window) ⇒ Screen
Returns a new instance of Screen.
13 14 15 |
# File 'lib/dommy/screen.rb', line 13 def initialize(window) @window = window end |
Instance Method Details
#__js_call__(method, _args) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/dommy/screen.rb', line 46 def __js_call__(method, _args) case method when "addEventListener", "removeEventListener" then nil when "dispatchEvent" then true end end |
#__js_get__(key) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dommy/screen.rb', line 17 def __js_get__(key) case key when "width", "availWidth" @window.inner_width when "height", "availHeight" @window.inner_height when "availLeft", "availTop" 0 when "colorDepth", "pixelDepth" 24 when "isExtended" false when "orientation" @orientation ||= ScreenOrientation.new(@window) else # Anything else is genuinely absent (JS `undefined`, `"x" in screen` # false) so feature detection takes the not-supported path. Bridge::ABSENT end end |