Search code examples
javascriptphantomjsscreenshotviewportbrowser-width

phantomjs image width not getting as expected


when i take screenshots using phanomjs using the following code works fine and I am getting width as 1920px and height is not a problem for me.

var webPage = require('webpage');
var page = webPage.create();

page.viewportSize = { width: 1920, height: 1080 };
page.open("http://www.google.com", function start(status) {
page.render('google_home.png');
 phantom.exit();

but, when i set the dimension as

page.viewportSize = { width: 320, height: 780 };

the resulting image width is 602px.

how to set width for taking screenshot using page.render() function?


Solution

  • Actually I can't. because "http://www.google.com" forcefully set the minimum width of the document above some 600px. so, when i call page.render() it renders the complete document which is having a width not 320px.