Guerrilla Guerrilla - 26 days ago 19
Javascript Question

page.clipRect causes page.render() to hang

I have this script for taking screenshots with PhantomJS:

var page = require('webpage').create();
page.open('https://github.com', function() {
page.viewportSize = { width: 320, height: 600 };
page.render('e:\\Screenshots\\test.png');
phantom.exit();


It works fine but I want to set the height of the viewport as it's currently the entire pages height.

The documentation says to use page.clipRect : http://phantomjs.org/screen-capture.html

But the below code doesn't work, it just hangs and never makes the screenshot:

var page = require('webpage').create();
page.open('https://github.com', function() {
page.viewportSize = { width: 320, height: 600 };
page.clipRect = { top: 0, left: 0, width: 320 height: 600 };
page.render('e:\\Screenshots\\test.png');
phantom.exit();


I get no error, just nothing happens and input stalls.

Any idea what is going on?

Answer

Just a plain old typo:

page.clipRect = { top: 0, left: 0, width: 320 height: 600 };

should be

page.clipRect = { top: 0, left: 0, width: 320, height: 600 };
                                             ^

But why would PhantomJS just hang there silently? There's a bug in v2 because of which errors won't show, so for now I use v1.9.8 to find syntax errors.

Comments