diff --git a/README.md b/README.md index dc69143..994cfbd 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ it also currently supports a couple of options screenshot = f.fetch( :output => '~/my_directory.png', # don't forget the extension! # optional: + :userAgent => 'Screencap browser', :div => '.header', # selector for a specific element to take screenshot of :width => 1024, :height => 768, diff --git a/lib/screencap/raster.js b/lib/screencap/raster.js index fd38745..74a2cf9 100644 --- a/lib/screencap/raster.js +++ b/lib/screencap/raster.js @@ -42,6 +42,7 @@ function pickupNamedArguments() { if(args.debug) { debug = true; } if(args.resourceWait) { resourceWait = args.resourceWait; } if(args.maxRenderWait) { maxRenderWait = args.maxRenderWait; } + if(args.userAgent) { page.settings.userAgent = args.userAgent; } } function setupMask() { @@ -75,46 +76,41 @@ function evaluateWithArgs(func) { function takeScreenshot() { page.open(args.url, function(status) { - if(status !== 'success') { - console.log('Unable to load: ' + args.url); - phantom.exit(); - } else { - page.includeJs( - "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js", - function() { - - var foundDiv = true; - page.evaluate(function(){ jQuery.noConflict(); }); - - if(args.div) { - var clip = evaluateWithArgs(withinPage_GetDivDimensions, args.div); - foundDiv = clip; - page.clipRect = clip; - } else if(mask) { - page.clipRect = mask; - } else if(args.height) { - // have a height resize the html & body to workaround https://github.com/ariya/phantomjs/issues/10619 - evaluateWithArgs( - function(w,h) { - jQuery('body, html').css({ - width: w + 'px', - height: h + 'px', - overflow: 'hidden' - }); - }, - page.viewportSize.width, - page.viewportSize.height - ); - } - - if(foundDiv) { - delayScreenshotForResources(); - } else { - phantom.exit(); - } - } - ); - } + page.includeJs( + "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js", + function() { + + var foundDiv = true; + page.evaluate(function(){ jQuery.noConflict(); }); + + if(args.div) { + var clip = evaluateWithArgs(withinPage_GetDivDimensions, args.div); + foundDiv = clip; + page.clipRect = clip; + } else if(mask) { + page.clipRect = mask; + } else if(args.height) { + // have a height resize the html & body to workaround https://github.com/ariya/phantomjs/issues/10619 + evaluateWithArgs( + function(w,h) { + jQuery('body, html').css({ + width: w + 'px', + height: h + 'px', + overflow: 'hidden' + }); + }, + page.viewportSize.width, + page.viewportSize.height + ); + } + + if(foundDiv) { + delayScreenshotForResources(); + } else { + phantom.exit(); + } + } + ); }); }