From 2478ed39713779b8e10caebb71d1afa3d3c1ee3a Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Thu, 3 Dec 2015 15:32:59 +0000 Subject: [PATCH] fix #345 --- lib/wraith/javascript/_phantom__common.js | 16 ++++++++++++---- lib/wraith/version.rb | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/wraith/javascript/_phantom__common.js b/lib/wraith/javascript/_phantom__common.js index a63a171b..282f78e3 100644 --- a/lib/wraith/javascript/_phantom__common.js +++ b/lib/wraith/javascript/_phantom__common.js @@ -33,7 +33,6 @@ module.exports = function (config) { currentDimensions = dimensions; } - page.viewportSize = { width: currentDimensions.viewportWidth, height: currentDimensions.viewportHeight}; page.settings = { loadImages: true, javascriptEnabled: javascriptEnabled }; // If you want to use additional phantomjs commands, place them here @@ -58,18 +57,27 @@ module.exports = function (config) { }); function runSetupJavaScriptThenCaptureImage() { + resize(); if (globalBeforeCaptureJS) { require(globalBeforeCaptureJS)(page); } if (pathBeforeCaptureJS) { require(pathBeforeCaptureJS)(page); } - captureImage(); + resizeAndCaptureImage(); } - function captureImage() { + function resize() { + page.viewportSize = { width: currentDimensions.viewportWidth, height: currentDimensions.viewportHeight}; + } + function resizeAndCaptureImage() { console.log('Snapping ' + url + ' at: ' + currentDimensions.viewportWidth + 'x' + currentDimensions.viewportHeight); + resize(); + setTimeout(captureImage, 1000); // give page time to re-render properly + } + + function captureImage() { page.clipRect = { top: 0, left: 0, @@ -82,7 +90,7 @@ module.exports = function (config) { if (helper.takingMultipleScreenshots(dimensions) && dimensionsProcessed < dimensions.length) { currentDimensions = dimensions[dimensionsProcessed]; image_name = helper.replaceImageNameWithDimensions(image_name, currentDimensions); - setTimeout(captureImage, 1000); + setTimeout(resizeAndCaptureImage, 1000); } else { // prevent CI from failing from 'Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL' errors diff --git a/lib/wraith/version.rb b/lib/wraith/version.rb index 96010fe4..a5f415b6 100644 --- a/lib/wraith/version.rb +++ b/lib/wraith/version.rb @@ -1,3 +1,3 @@ module Wraith - VERSION = "3.0.3" + VERSION = "3.0.4" end