Reputation: 2732
Is there a way to specify viewport size for PhantomJS as a command line argument?
Upvotes: 5
Views: 2559
Reputation: 2031
You can try this:
var args = require('system').args,
viewportSize = {width: 1280, height: 1024},
page = require('webpage').create();
if (args.length >= 1) {
args.forEach(function(arg, i) {
if (arg.match(/^[0-9]+x[0-9]+$/)) {
var viewportParts = arg.split('x');
viewportSize = {width: viewportParts[0], height: viewportParts[1]};
}
});
}
page.viewportSize = viewportSize;
Then run your script and add 320x480 after the script name, for example…
Upvotes: 2
Reputation:
Of course. You'll have to process the command line arguments yourself using system.args looking for your custom option of viewport
or whatever you decide to call it and plucking out its value. Then set page.viewportSize to an appropriate value using the provided argument value.
Upvotes: 1