baudehlo / node-phantom-simple

Simple bridge to phantomjs for Node
MIT License
201 stars 70 forks source link

How to set the viewportSize when using Slimer.js? #150

Closed syedfaizan closed 7 years ago

syedfaizan commented 7 years ago

I got this working perfectly , but i need to get a screenshot of higher resolution.

i tried this

var driver = require('node-phantom-simple');
driver.create({ path: 'node_modules/slimerjs/src/slimerjs' }, function (err, browser) {
  browser.viewportSize = { width:1920, height:1080 }; // didn't work
  return browser.createPage(function (err, page) {
    page.viewportSize = { width:1920, height:1080 }; // also didn't work

    // render page as screenshot here

    browser.exit();
  })
});

please help.

Reewr commented 7 years ago

Try the following:


var driver = require('node-phantom-simple');
driver.create({ path: 'node_modules/slimerjs/src/slimerjs' }, function (err, browser) {
  return browser.createPage(function (err, page) {
    page.set('viewportSize', { width:1920, height:1080 }, function(err) {
      // Viewport has been set.
    });

    // render page as screenshot here

    browser.exit();
  });
});
syedfaizan commented 7 years ago

@Reewr Thanks buddy, that did it :+1: