Saturday, August 29, 2015

iOS 8 Safari screenshots with variable browser header height

Capturing shots when a browser has variable header height
In iOS 8 Safari comes with a feature when browser's header might be 65px or 41px (when address bar is hidden on scroll, aka minimal-ui) .


For example to capture pages on iPad 2 one could use AShot utility with a strategy that can detect current height of browser's header.

int minHeader = 41;
int maxHeader = 65;
int minViewPortHeight = 960; // Height of viewport when address bar shown
HeaderDetectionStrategy strategy =
    new VariableHeaderDetectionStrategy(minHeader, maxHeader, minViewPortHeight);
new AShot()
  .shootingStrategy(new ViewportPastingStrategy(strategy))
  .takeScreenshot(webDriver);
When in JavaScript to guess the height of browser's header - whether address bar is shown, window.innerHeight property could be used.