Shouldn't the output from this PhantomJS script be 240x320 pixels? I'm getting a large, default-sized image. clipRect() would seem to render the correct size image, but I need the responsive content of the page to reflect the actual browser window size.
var page = require('webpage').create();
page.viewportSize = { width: 240, height: 320 };
page.open('http://cnn.com', function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render('default.png');
phantom.exit();
}, 200);
}
});
This is a known issue but I found a workaround:
There is code to do it in this repository: https://github.com/jbeuckm/Splasher
This works!! Found the snippet on the github page of the issue.It forces the 'body' element to the page viewportSize:
This seems to work in the Mac binary for 1.9.7:
In CasperJS, I dealt with this issue, used the above method(s), and ultimately found it was unnecessary (at least for me, in CasperJS) once I set the single viewport options via the
casper.viewport()
method.I've posted my version below, so you can see how it could work with many urls at once.