Reputation: 1
I have do some stuff like:
page.onInitialized = function(){
window.screen = {width:320, height:640}
})
It works just in one DOM , if the document has another DOM(like a document has a iframe). that one's screen is 1024 * 768. I cant change it in iframe before iframe's document loaded.
Updated:
Phantomjs default screen resolution is 1024 * 768 when it run in background,but I want to change it to 320 * 640.
And, viewportSize effectively simulates the size of the window(NOT SCREEN RESOLUTION).
Upvotes: 0
Views: 236
Reputation:
You can change it only within onInitialized
callback:
function on_init (page){
var width='320',height='640';
//page.viewportSize = {width:width,height:height}
page.evaluate(function (width,height){
screen = {width:width,height:height,availWidth:width,availHeight:height};// window.screen object
//innerWidth=width; innerHeight=height; outerWidth=width; outerHeight=height;
},width,height);};
var page = require('webpage').create(); page.onInitialized=function(){on_init(page)}
Upvotes: 1
Reputation: 16856
Can you just set the viewport default size before opening the page?
page.viewportSize = { width: 320, height: 640 };
Upvotes: 0