Created
July 8, 2014 18:13
-
-
Save jzelenkov/47aa0e2430a37f642437 to your computer and use it in GitHub Desktop.
jar of cookies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var page = require('webpage').create() | |
var args = require('system').args | |
var argv = require('optimist').argv | |
var url = args[1] | |
var resolution = args[2] | |
var width = resolution.split('x')[0] | |
var height = resolution.split('x')[1] | |
var timeout = args[3] | |
var cut = args[4] == 'true' | |
var cookies = argv.cookie | |
page.viewportSize = { | |
width : width, | |
height : height | |
} | |
if (cut) page.clipRect = { | |
top: 0, | |
left: 0, | |
width: width, | |
height: height | |
} | |
if (cookies) { | |
// convert to array even if we have a single entry | |
if (!Array.isArray(cookies)) cookies = [cookies]; | |
cookies.forEach(function(cookie) { | |
phantom.addCookie(JSON.parse(cookies)) | |
}) | |
} | |
// silence phantomjs | |
page.onConsoleMessage = function () {} | |
page.onConfirm = function () {} | |
page.onPrompt = function () {} | |
page.onError = function () {} | |
page.open(url, function (status) { | |
if (status !== 'success') throw 'Unable to load' | |
window.setTimeout(function () { | |
console.log(page.renderBase64('PNG')) | |
phantom.exit() | |
}, timeout) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment