I need to override screen object.
I used exapmples from here How do I override window.screen? and here http://phantomjs.org/api/webpage/handler/on-initialized.html
But my code does not work.
PhantomJSDriver phantom = new PhantomJSDriver(caps);
phantom.executePhantomJS("onInitialized = function() {\n" +
" evaluate(function() {\n" +
" window.screen.availWidth = 1024;\n" +
" window.screen.availHeight = 768;\n" +
" });\n" +
"};");
System.out.println(phantom.executeScript("return window.screen;"));
phantom.get("http://www.browserleaks.com/javascript");
System.out.println(phantom.executeScript("return window.screen;"));
Here is my console output:
{availWidth=1440, pixelDepth=32, availTop=0, width=1440, colorDepth=32, availLeft=0, availHeight=860, height=900}
{availWidth=1440, pixelDepth=32, availTop=0, width=1440, colorDepth=32, availLeft=0, availHeight=860, height=900}
Note that this line:
webDriver.manage().window().setSize(new Dimension(980, 1461));
changes only availWidth
and availHeight
properties in screen object.
Can anyone suggest me how to override all properties in screen object?