Skip to content

Screenshot scale parameter and scroll position #301

@lanks

Description

@lanks

I am having an issue when capturing screenshots using the screenshot scale parameter when the page is scrolled vertically.

In this case rather than taking a screenshot of the current viewport, the screenshot shows the viewport offset from the top. This means that the top of the page is just blank and then only part of the viewport is shown.

Here's an example of how I am scrolling the page (note I am showing a specific element on screen).
scroll_script = <<-JS let element = document.getElementById("salesmock-#{prev_step[:step].id}"); let dims = element.getBoundingClientRect(); window.scrollTo(window.scrollX, (dims.top - dims.height) + #{step.scroll_padding}); JS browser.execute(scroll_script)

Taking the screenshot:
browser.screenshot(path: file, scale: 1.8)

I had a look into the ferrum code and I see that in screenshot.rb the area_options function sets x, y to 0,0 when the scale is not 1... I was wondering if this might be the cause of the issue?

def area_options(full, selector, scale)
      message = "Ignoring :selector in #screenshot since full: true was given at #{caller(1..1).first}"
      warn(message) if full && selector

      clip = if full
               width, height = document_size
               { x: 0, y: 0, width: width, height: height, scale: scale } if width.positive? && height.positive?
             elsif selector
               bounding_rect(selector).merge(scale: scale)
             end

      if scale != 1
        unless clip
          width, height = viewport_size
          clip = { x: 0, y: 0, width: width, height: height }
        end

        clip.merge!(scale: scale)
      end

      clip
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions