0

Is it possible to change the screen dimensions as reported by screen.availWidth and screen.availHeight in PhantomJS 2.x? Although it is possible to specify the window size, it seems that the screen dimensions are always reported as 1024x768.

Note: although the solution for How do I override window.screen? works, I find it somewhat hacky and was wondering if there is a better way.

Community
  • 1
  • 1
Rubrick
  • 308
  • 5
  • 13
  • 1
    I don't see how that solution is hacky, can you clarify? It's executing code inside a phantomjs event function. Many libraries have event life cycles to handle this sort of execution. – Chris Hawkes May 04 '16 at 14:57
  • I don't mind implementing life cycle methods, it's just that manually overwriting (monkeypatching) properties of a standard javascript object does not feel good. I would have expected that PhantomJS would have some other way of specifying properties of the environment at startup. – Rubrick May 08 '16 at 13:42

1 Answers1

0

If you are using java, it can be done like this:

driver = new PhantomJSDriver(desiredCapabilities);
driver.manage().window().setSize(new Dimension(1024, 768));

Sri
  • 293
  • 3
  • 11