diff --git a/lib/trmnlp/screenshot.rb b/lib/trmnlp/screenshot.rb index 131aa3e..a60d54c 100644 --- a/lib/trmnlp/screenshot.rb +++ b/lib/trmnlp/screenshot.rb @@ -69,9 +69,13 @@ class Screenshot })(); JS + # The preview frame has the device's CSS size, so the screen stays unscaled there. + LIVE_PREVIEW_SIZE_STYLE = '' + def self.live_preview(html) timeout = html.match?(MAPS_DOCUMENT_PATTERN) ? READINESS_TIMEOUT_WITH_MAPS_SECONDS : READINESS_TIMEOUT_SECONDS - html.sub('', "#{LAYOUT_PASS_STYLE}") + script = "" + html.sub('', "#{LIVE_PREVIEW_SIZE_STYLE}#{LAYOUT_PASS_STYLE}#{script}") end def initialize(pool:, viewport_timeout: 5, fonts_timeout: FONTS_TIMEOUT_SECONDS) diff --git a/spec/lib/trmnlp/app_spec.rb b/spec/lib/trmnlp/app_spec.rb index 0726330..728e2c3 100644 --- a/spec/lib/trmnlp/app_spec.rb +++ b/spec/lib/trmnlp/app_spec.rb @@ -214,9 +214,9 @@ def in_browser(page) expect(in_browser(page) { it.execute_script("return #{shown}") }).to eq(unscaled(page)) end - it 'shows the screen at the size of the device' do + it 'shows the screen at its CSS size, the size of the preview frame' do width = 'return document.querySelector(".screen").getBoundingClientRect().width' - expect(in_browser(preview(table)) { it.execute_script(width) }).to eq(1872) + expect(in_browser(preview(table)) { it.execute_script(width) }).to eq(1040) end end